import java.sql.*;
public class main{
public static void main(String[] args) {
Connection con;
Statement sta;
ResultSet res;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/zxk?useSSL=false&serverTimezone=UTC&user=root&password=root");
sta=con.createStatement();
res=sta.executeQuery("select * from student");
while (res.next()){
String id=res.getString(1);
String name=res.getString(2);
System.out.println("id:"+id+"name:"+name);
}
con.close();
sta.close();
res.close();
}catch (Exception e){
System.out.println("有错误");
}
}
}
java连接mysql8.0
最新推荐文章于 2024-05-12 02:02:00 发布