0

I'm beginner in android develop. I have a oracle database in remote system and I want to connect database from my android app. I used below code for connect but I can't connect to it (with ojdbc14.jar library). /n have you Ideas???

try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
                String url = "jdbc:oracle:thin:@//192.20.xx.xxx:1521/SHOP47";

                Connection conn =
                        DriverManager.getConnection(url, "user", "pass");

                conn.setAutoCommit(false);
                Statement stmt = conn.createStatement();
                ResultSet rset =
                        stmt.executeQuery("select count(1) from GOODS");
                while (rset.next()) {
                    Toast.makeText(getBaseContext(),rset.getString(1).toString(), Toast.LENGTH_SHORT).show();

                }
                stmt.close();
            }
            catch(Exception e){
             Log.d(TAG,e.getMessage());
            }
2
  • 2
    You should not do this anyhow. It is much too risky to directly connect to the database. Use a service layer in between that is connected by the clients. Commented Feb 4, 2018 at 6:06
  • Don't do this. Create web service for this purpose and utilize them in you android app. Commented Feb 4, 2018 at 6:20

1 Answer 1

2

Actually, you shouldn't do this directly from an android application, because:

  1. Android applications are really easy to decompile or to reverse engineer, and the client or the person decompiling will have credentials to access your database. If using the right hacking tools like Backtrack, then this malicious client can access, connect and exploit the data in your database.
  2. If your application is for clients all around the world, then the clients should open and maintain a connection to your database per operation or set of operations. Opening a physical database connection takes a lot of time and resources, even when your pc client is in a LAN next to the database engine server.

A better solution would be to use a service-oriented architecture where you will have at least two applications:

  1. Service provider application. This application will create and publish web services (preferably RESTful) and may establish policies to consume the web services like user authentication and authorization. This application will also connect to the database and execute CRUD operations against it.
  2. Service consumer application. This would be your Android (or any other mobile) application.

In Android, you can create a Restful Service Layer that will have methods for each service.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.