What is the best way to connect between android an

2020-02-09 09:00发布

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

8条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-09 09:39

Have a look to my Android-Oracle Connectivity blog post. That will hopefully help you. If still you have problem. Let me know about it.

查看更多
\"骚年 ilove
3楼-- · 2020-02-09 09:40

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

查看更多
闹够了就滚
4楼-- · 2020-02-09 09:42

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)

查看更多
够拽才男人
5楼-- · 2020-02-09 09:49

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.

查看更多
老娘就宠你
6楼-- · 2020-02-09 09:52

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

查看更多
Juvenile、少年°
7楼-- · 2020-02-09 09:59

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 .

查看更多
登录 后发表回答