当前位置:Gxlcms > mysql > jdbc-安卓新手用JDBC连接mysql时一直报错

jdbc-安卓新手用JDBC连接mysql时一直报错

时间:2021-07-01 10:21:17 帮助过:92人阅读

mysqljdbc数据库android

抛出异常在logcat提示:驱动连接成功,数据库连接失败Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo。求大神帮忙,错误围绕好长时间了

连接代码

 //连接数据库 public static Connection getCon() {  Connection conn = null;  try {   Class.forName("org.gjt.mm.mysql.Driver");   System.out.println("驱动连接成功");  } catch (ClassNotFoundException e1) {   // TODO Auto-generated catch block   System.out.println("驱动连接失败");  }     String dbUrl = "jdbc:mysql://localhost:3306/student";     String username = "root";     String psw = "1234";  try {   conn = DriverManager.getConnection(dbUrl,username,psw);  } catch (SQLException e) {   // TODO Auto-generated catch block   System.out.println("数据库连接失败"+e);  }  return conn; }

人气教程排行