How To Connect Android With Oracle Database?
I am new to android development. I want to develop a android application that update data from a oracle database. Could anyone help me out? Thanks in advance.
Solution 1:
Use Apache Server to connect android to pc
In php.ini open oci8.dll
in htdocs make php file. Your php code is
<?PHP$con=
"(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Your_ip)(PORT = 1521))
(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = Your_db_name)
)
)";
$conn = ocilogon( "User_name", "Password",$con,"WE8ISO8859P15");
$query = "select * from table_name";
$parseresults = ociparse($conn, $query);
ociexecute($parseresults);
while($row=oci_fetch_assoc($parseresults))
$output[]=$row;
print json_encode($output);
oci_free_statement($parseresults);
oci_close($conn);
?>
In android:
publicclassUploadActivityextendsAsyncTask<Void, Void, String> {
Context context;
String result;
publicUploadActivity(Context context) {
this.context = context;
}
@SuppressWarnings("static-access")
@OverrideprotectedvoidonPreExecute() {
super.onPreExecute();
}
@OverrideprotectedStringdoInBackground(Void... params) {
// TODO Auto-generated method stub
final List<Pair<String, String>> postParameters = newArrayList<>();
for (int i = 0; i < activity[0].length; i++) {
//postParameters.add(new Pair<>("var1", activity[i][0]);
result = null;
try {
String response = CustomHttpClient.execute(
URL + "Your_php.php", postParameters);
result = response.toString();
result = result.replaceAll("(\r\n|\n)", "");
} catch (Exception e) {
Log.e("log_tag_ms", "Error in http connection!!" + e.toString());
}
}
returnnull;
}
protectedvoidonPostExecute(String result) {
super.onPostExecute(result);
} }
Post a Comment for "How To Connect Android With Oracle Database?"