What is the best way to connect between android and oracle database?

前端 未结 7 524
后悔当初
后悔当初 2020-12-09 19:48

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

相关标签:
7条回答
  • 2020-12-09 19:54

    You have (at least) two options:

    1. Use Oracle Database Mobile Server. (Best, safest bet)

    2. Download the JDBC Drivers and connect that way. (Not recommended, unsafe - especially for over-the-air connectivity)

    0 讨论(0)
  • 2020-12-09 19:59

    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...

    0 讨论(0)
  • 2020-12-09 20:01

    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 .

    0 讨论(0)
  • 2020-12-09 20:02

    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

    0 讨论(0)
  • 2020-12-09 20:03

    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".

    0 讨论(0)
  • 2020-12-09 20:06

    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.

    0 讨论(0)
提交回复
热议问题