ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
![](https://box.kancloud.cn/a4b8c9c54479dbb429f1f13b59a40dfa_623x396.png) ![](https://box.kancloud.cn/ebd9982e6017a9f7e6b0e3829d872361_620x371.png) ![](https://box.kancloud.cn/71d5ee8b3d5c34feb9c8829a1be84b18_641x293.png) query .java ~~~ package zyw.crud; import java.sql.*; public class query { public static void main(String[] args) throws SQLException, ClassNotFoundException { // 1、注册数据库的驱动 Class.forName("com.mysql.jdbc.Driver"); // 2.获取数据库连接 String url="jdbc:mysql://122.14.200.136:3306/javadb"; Connection connection = DriverManager.getConnection(url, "root", "6a133f0024"); //3.获取操作数据库的对象 Statement statement= connection.createStatement(); String sql = "select * from xuesheng"; ResultSet resultSet=statement.executeQuery(sql); //4.遍历结果集,取出数据 while (resultSet.next()){ String name=resultSet.getString("xingming"); Integer age=resultSet.getInt("nianling"); System.out.println("姓名:"+name+"年龄:"+age); } //5.关闭对象 resultSet.close(); statement.close(); connection.close(); } } ~~~ ![](https://box.kancloud.cn/860e503a93516bb8cf49de004e6e4e35_537x211.png)