// 查询表test_01中的所有数据
public class JDBCUtilsSelectTest {
public static void main(String[] args) throws SQLException {
// 1。获取连接
Connection conn = JDBCUtils.getConnection();
// 2。获取语句执行平台,即Statement对象
Statement sqlExecute = JDBCUtils.createStatement(conn);
// 3。执行sql语句
String sql = "select * from test_01;";
ResultSet resultSet = sqlExecute.executeQuery(sql);
// 4。处理结果集
while(resultSet.next()){
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("id = " + id + ", name = " + name + ", age = " + age);
}
// 5。关闭对象
JDBCUtils.close(conn,sqlExecute,resultSet);
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论