android odbc connection for oracle 10g [duplicate]

2019-07-31 10:49发布

问题:

Possible Duplicate:
android jdbc odbc connection

before i used oracle database 11g for my android application and successfully stored values. Unfortunately my oracle database 11g could not open due to some problem . I uninstalled oracle 11g and installed oracle database 10g edition. now i compiled program and close emulator and open table in oracle the values could not be stored . I dont know how this problem occur. Here in my code i put port number 1521 and sid is 'orcl' and table name is 'sample'. Pls give one solution and any changes in port number and sid . Thanks in advance

      package com.search;

      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;

      import android.app.Activity;
      import android.os.Bundle;

     public class OraclesearchActivity extends Activity {
   /** Called when the activity is first created. */
    @Override
     public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String a="karthick";
    String b="vijay";
    String c="vel";
    try
    {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

        Connection         con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.2:1521:orcl","system","words");

        PreparedStatement pst=con.prepareStatement("insert into sample(first,middle,last)values(?,?,?)");
        pst.setString(1,a);
        pst.setString(2,b);
        pst.setString(3,c);
        pst.executeUpdate();

    }
    catch(Exception e)
    {
        System.out.println("Exception:"+e);
    }
}
 }

回答1:

Probably not the answer youre looking for but I would seriously question the wisdom of having a mobile device connect directly to oracle, or any dbms.

Instead, consider putting a REST or SOAP service in front of your dbms and let your mobile apps connect to that.

Some of the benefits include:

  • When your dbms or dbms drivers change versions, you only have to update your service...not potentially lots of mobile devices.
  • You dont have the credentials to your dbms on a mobile device which potentially gets lost or otherwise ends up in hostile environment where someone can try to brute force whatever way youve attempted to secure the credentials.
  • Your service can support lots of different kinds of clients/mobile devices without having to worry about finding an oracle driver for that device, say iOS, for example.
  • You can more gracefully handle service outage / planned downtime via the service...announcing unavailability or alternatives via service responses, rather than just not being able to get a connection which could be indistinguishable from bad network connections.
  • You'll have a wealth of options for augmenting the service with various caching options, validations, and applying finer grained or context specific authorization than what you might want to implement in oracle. -

Perhaps you really have some hard requirement to connect directly but I think that would be a rare and very specific requirement. The much more common practice seems to be to buffer the connection with a service layer that gives you much more flexibility, IMHO.

Good luck.



回答2:

I agree with the first answer, connecting mobile devices directly to an RDBMS is not recommended. There are serious security implications to this, not to mention performance and other implications.

If you don't want to go to the trouble of building out your own web service, there is a way to handle it at the database level. Oracle actually offers a product specifically designed for this. It's called Database Mobile Server.

http://www.oracle.com/technetwork/products/database-mobile-server/overview/index.html

You can read about it there, also download and try it out from the download tab. In addition to Oracle Database, you'll need an app server. WebLogic or Glassfish are recommended.

It offers several advantages, the main one being the ability to synchronize SQLite data from Android devices with an Oracle backend without any additional development effort. You get the ability for the app to function in disconnected mode as well.

Good luck with your project.

Eric Jensen, Oracle PM