简体   繁体   中英

How to connect to an oracle database in android?

I have an oracle database, i need to access to the info but i can't. I have imported the OJDBC6 driver, I created the class:

public class JDBC_ORA    {
     static String userName="XXX";
     static String password="X";
     static String server="192.168.X.X";

     public Connection con;

     public void conexion() {        
         try {          
             Class.forName("oracle.jdbc.driver.OracleDriver");
             con = DriverManager.getConnection("jdbc:oracle:thin:" + userName + "/" + password+ "@"+server);            

         } catch (ClassNotFoundException e) {
             e.printStackTrace();
         } catch (SQLException e) {
             e.printStackTrace();
         } 
     }


     public void cerrar (Connection con) {
         try {
             con.close();
         } catch (SQLException e) {
             e.printStackTrace();

         }
     }
}

And i call it in the mainactivity:

 JDBC_ORA ora_con = new JDBC_ORA();   
    ora_con.conexion();
    try {
        Statement stmt = ora_con.con.createStatement();
        rset = stmt.executeQuery("select * from asdf where cid='"+ var + "'" );
        while (rset.next())
        {
            System.out.println(blablablabla);
            ora_con.con.commit();
        }
        stmt.close();
        ora_con.cerrar(ora_con.con);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

And always get this errors

Could not find class 'oracle.security.pki.OraclePKIProvider', referenced from method oracle.jdbc.driver.OracleDriver.<clinit>

Could not find class 'javax.management.MBeanServer', referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans

Can someone help me please?

Don't. If you do this, you have to put your password in the app. That means your database is totally insecure, and can be accessed by anyone with a copy of the app and 5 minutes to decompile it. Instead, use a webservice that sits between your app and the database. That way you never need the password to leave your machines.

The best practice will be using a web-service written in Java,.Net, PHP, etc.. Then you need to connect your application with that web-service you created. The other way is to use Oracle Database Mobile Server .

You could find how to create web-service easily on google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM