Reputation: 302
I need to access data from an external oracle database from my application android to update the local database application, but I don't know what would be the best way to do it. Would I need to create a web service to access to the oracle database or there is another simple way?
Thanks
Upvotes: 12
Views: 53492
Reputation: 121
ORACLE DATABASE CONNECTION WITH ANDROID THROUGH LAN
Grant Some Manifest Permissions
<permission
android:name="info.android.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.android.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
MainActivity Class
package example.com.myapplication;
import java.sql.Connection;
import java.sql.DriverManager;
import android.os.StrictMode;
public class MainActivity extends AppCompatActivity {
private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DEFAULT_URL = "jdbc:oracle:thin:@192.168.0.1:1521:xe";
private static final String DEFAULT_USERNAME = "system";
private static final String DEFAULT_PASSWORD = "oracle";
private Connection connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
TextView tv = (TextView) findViewById(R.id.hello);
try {
this.connection = createConnection();
e.Log("Connected");
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery("select * from cat");
while(rs.next()) {
System.out.println("hello : " + rs.getString(1));
}
connection.close();
}
catch (Exception e) {
e.Log(""+e);
e.printStackTrace();
}
}
public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException {
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
public static Connection createConnection() throws ClassNotFoundException, SQLException {
return createConnection(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
}
}
Prerequisite are: Note there is no need to add dependency lib ojdbc14.jar just copy ojdbc14.jar to your JAVA_HOME jre -> lib -> ext & paste here ojdbc14.jar then first manually check jdbc connection by cmd/terminal make any simple java program http://www.javatpoint.com/example-to-connect-to-the-oracle-database
Upvotes: 0
Reputation: 75
There is a simpler way than writing a WebService and still keeping the same level of security: use a Virtual JDBC Driver that uses a three-tier architecture: your JDBC code is sent through HTTP to a remote Servlet that filters the JDBC code (configuration & security) before passing it to the Oracle JDBC Driver. The result is sent you back through HTTP. There are some free software that use this technique. Just Google " Android JDBC Driver over HTTP".
Upvotes: 0
Reputation: 839
Also there is one robust 3-tier architecture using SAP-Sybase(Middle wire) with ORACLE. Connect your Sybase DB to ORACLE with JTDS driver. Then, use your generating code in Android. For reference : SQL Server and Sybase Databases
Upvotes: 0
Reputation: 216
I think there is no direct way to connect android apps with oracle db. for this purpose you need to web service of php or java or .net . according to me php is best way to connect android apps with external database . for this u have to need a host a one php page.this page makes directly connection with oracle database. for connecting android apps with php page u need a json parsing which is easy to do in android apps development .
Upvotes: 0
Reputation: 22859
You have (at least) two options:
Use Oracle Database Mobile Server. (Best, safest bet)
Download the JDBC Drivers and connect that way. (Not recommended, unsafe - especially for over-the-air connectivity)
Upvotes: 20
Reputation: 6942
in Android you can only directly connect with SQLiteDatabase.. if you want to connect with MYSQL or Oracle it is necessory that you have to make web service whether it will be on PHP, .NET or on JSP.. but without web service you can not use oracle in android...
it also can done through JDBC connectivity but i dnt have exact example of that...
Upvotes: 0
Reputation: 29632
You can not directly access the Oracle database from android Application. you need to create webservices in PHP, .net or in Java to make connection with Oracle Database. After creating this webservice , you need to connect your application with the webservice. This is the simplest way of connecting with Oracle Database.
Upvotes: 0