0

I am attempting to perform a simple query on a database in an android application. But the program crashes every time the method is performed. Does anyone have any suggestions on how to fix this?

Here is the error log message:

07-15 17:20:23.623: ERROR/AndroidRuntime(544): Uncaught handler: thread main exiting due to uncaught exception 07-15 17:20:23.643: ERROR/AndroidRuntime(544): java.lang.VerifyError: com.mysql.jdbc.MysqlIO 07-15 17:20:23.643: ERROR/AndroidRuntime(544): at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771) 07-15 17:20:23.643: ERROR/AndroidRuntime(544): at com.mysql.jdbc.Connection.(Connection.java:1555) 07-15 17:20:23.643: ERROR/AndroidRuntime(544): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 07-15 17:20:23.643: ERROR/AndroidRuntime(544): at java.sql.DriverManager.getConnection(DriverManager.java:191) 07-15 17:20:23.643: ERROR/AndroidRuntime(544): at java.sql.DriverManager.getConnection(DriverManager.java:226)

Here is my connection:

String url = "jdbc:mysql://192.126.0.1:3306/";
        String db = "db";
        String driver = "com.mysql.jdbc.Driver";
        String table = "table";
        Connection conn = null;

        try {
            Class.forName(driver);
            try {
                conn = DriverManager.getConnection(url+db,"root","");

                conn.close();

            } catch (SQLException s) {
                s.printStackTrace();
            }
        } catch (ClassNotFoundException cnfe){
            System.out.println("ERROR");
        }
scriptdiddy
  • 1,207
  • 3
  • 17
  • 31

2 Answers2

1

You have a different version of the JDBC driver in your compile time environment, and a different one in your runtime environment. Scan your disk and device for mysql-connector*.jar and make sure that you have only one around.

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75
0

Im working on an android app with online mysql db as well. I think you cant connect it directly like in java applications. You should write php files and put them on a server. They will connect to the db and send you data inJSON...

dumazy
  • 13,857
  • 12
  • 66
  • 113