How can I connect Android to an Oracle database?

1152740 pts.
Tags:
Android
Oracle Database
I really need to access data from an external Oracle database through an Android application (so I can actually update the local database application). I'm not sure what's the best way to do it. Should I create a web service to access it or is there another way?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
Hi, try this code in android java class… replace your Oracle db credentials…

public class ConnectToOracle {
  
  public static void main(String[] args) {
 
    Connection connection = null;
    try {
 
  // Load the Oracle JDBC driver
 
  String driverName = "oracle.jdbc.driver.OracleDriver";
 
  Class.forName(driverName);
 
 
  // Create a connection to the database
 
  String serverName = "localhost";
 
  String serverPort = "1521";
 
  String sid = "mySchema";
 
  String url = "jdbc:oracle:thin:@" + serverName + ":" + serverPort + ":" + sid;
 
  String username = "username";
 
  String password = "password";
 
  connection = DriverManager.getConnection(url, username, password);
 
   
 
  System.out.println("Successfully Connected to the database!");
 
   
    } catch (ClassNotFoundException e) {
 
  System.out.println("Could not find the database driver " + e.getMessage());
    } catch (SQLException e) {
 
  System.out.println("Could not connect to the database " + e.getMessage());
    }
 
 }
 
}

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    I've never used Oracle mobile server, but it looks promising.

    If for any reason it doesn't meet your needs, a web service would be the way to go.
    85,430 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: