时间:2021-07-01 10:21:17 帮助过:3人阅读
我们可以使用JDBC查询来执行select语句。
try(Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD)){
try(Statement stmt = conn.getStatement()){
try(ResultSet rs = stmt.executeQuery("select * from students where gender=\'M\';")){
while(rs.next()){
long id = rs.getLong(1); //注意:索引从1开始
long classId = rs.getLong(2);
String name = rs.getString(3);
String gender = rs.getString(4);
}
}
}
}
廖雪峰Java15JDBC编程-3JDBC接口-2JDBC查询
标签:tco 语句 索引 from cut 查询 stat ssid str