1
// 查询表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);
    }
}

chain_xx_wdm
64 声望2 粉丝

1.领养代替买卖