jdbc-安卓新手用JDBC连接mysql时一直报错
程序员文章站
2022-04-25 18:59:07
...
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; }
上一篇: php面向对象之类与实例化对象
下一篇: spring-mysql连接8小时后异常