62,627
社区成员
发帖
与我相关
我的任务
分享
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/opensource_students?useSSL=true&characterEncoding=UTF-8";
String user="root";
String password="";
conn=DriverManager.getConnection(url,user,password);
System.out.println("连接成功,喜大普奔");
String sql="select * from mess where number=00004";
// PreparedStatement ptmt=conn.prepareStatement(sql);
// ptmt.setString(1, number);
// ResultSet rs=ptmt.executeQuery();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery(sql);
String name=rs.getString("name");
System.out.println(name);
}catch(Exception e2){
System.out.println("又TM连接失败了");
}
我曾经也碰到过,看报错就能解决了,你把报错那个e2打印出来
用代码连接数据库,不支持无密码的,设置个密码就行了,要是不保险,可以设置个其他用户,root给自己用

