0

Hi i'm trying to do an android application and i need to connect to an external database but when i load jdbc driver, the system give me an error this is the code, the error is on Class.forName("com.mysql.jdbc.Driver"); I review the path of jdbc driver but it is correct, any idea?

private void connDB(String username, String password, Intent intent){

      try{

        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://ip/dbname?", "username", "password");
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM id");
        rs = stmt.getResultSet();

        if (stmt.execute("SELECT * FROM id")) {
            rs = stmt.getResultSet();
        }


        while (rs.next()) {
            //get id
            id1 = rs.getInt("id");
            id.add(id1);
            //get name
            buff = rs.getString("id");
            user_name.add(buff);
            //get password
            buff = rs.getString("id");
            user_password.add(buff);
        }
        imax = id.size();

        for(i=0; i<imax; i++){
            if(MainClass.username.equals(user_name.get(i)) && MainClass.password.equals(user_password.get(i))){
                startActivity(intent);
                idUser = id.get(i);
                break;
            }
            else{

                System.out.println("error");
            }
        }

    }
        catch (Exception ex){
            System.out.println("SQLException: " + ex.getMessage());

        }
        finally {


            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException sqlEx) { } // ignore
                    rs = null;
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException sqlEx) { } // ignore
                    stmt = null;
            }
        }



java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)

all are system err

golia
  • 95
  • 1
  • 1
  • 6

0 Answers0