So people are probably going to tell me this is a bad idea, but I'd like to at least give it a go.
EDIT The intention of this app is that it can only work when the device is part of the same network the oracle db is on or is connected to the network via VPN. The information in the database is not going to be globally accessible, which is why I will need direct connection to the oracle db.
Now according to this thread
Connecting the oracle in android application
He was successful in querying the oracle db.
So I have a fairly basic class that when initialised will try to get a connection to my database.
package com.producermobile;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import android.util.Log;
public class ConnectOra {
private Connection conn;
private Statement stmt;
public ConnectOra() throws ClassNotFoundException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@x.x.x.x:1521:PR10";
this.conn = DriverManager.getConnection(url,"xxx","xxx");
this.conn.setAutoCommit(false);
this.stmt = this.conn.createStatement();
} catch(SQLException e) {
Log.d("tag", e.getMessage());
}
}
public ResultSet getResult() throws SQLException {
ResultSet rset = stmt.executeQuery("select customer from customers");
stmt.close();
return rset;
}
}
And in my main activity onCreate method I have this
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
ConnectOra db = new ConnectOra();
ResultSet rs = db.getResult();
ArrayList<String> list = new ArrayList<String>();
while(rs.next()) {
list.add(rs.getString(1));
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, list));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
} catch(Exception e) {
}
}
In Eclipse I add the external ojdbc14.jar file to the build path.
However when I run
this.conn = DriverManager.getConnection(url,"xxx","xxx");
I receive the following exception
"Io exception: The Network Adapter could not establish the connection"
If however I create an instance of this class inside a standard java app with a main method, the connection works. Any ideas?