Java通过mysql-connector-java-8.0.11连接MySQL

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yuxisanno139/article/details/80835835
  • driver = “com.mysql.cj.jdbc.Driver”;
  • url=”jdbc:mysql://127.0.0.1:3306/Users?useSSL=true&serverTimezone=GMT”;
  • Mysql的ResultSet 索引是从1开始的

Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Users?useSSL=true&serverTimezone=GMT", "root", "root");
PreparedStatement ps = conn.prepareStatement("select * from t_users");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
User user = new User();
user.setId(rs.getInt(1));
user.setUuid(rs.getString(2));
user.setName(rs.getString(3));
user.setPassword(rs.getString(4));
System.out.println(user);
}
rs.close();
ps.close();
conn.close();

展开阅读全文

没有更多推荐了,返回首页