next()
当没有下一行就返回fales
previous()
向上一行移动,没有就返回fales
两种写法
方法1的写法更加灵活
方法2依赖位列数据
public class Main1 {
public static void main(String[] args) throws Exception{
String url = "jdbc:mysql://127.0.0.1:3306/fzhl_";
String user = "root";
String pass = "root";
Connection connection = DriverManager.getConnection(url,user,pass);
String sql = "select * from fz03";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
// 方法1
ResultSet resultSet = preparedStatement.executeQuery(sql);
while (resultSet.next()){
System.out.println(resultSet.getString("name")+" "
+resultSet.getString("x")+" "+resultSet.getInt("age"));
}
// 方法2
ResultSet resultSet1 = preparedStatement.executeQuery(sql);
while (resultSet1.next()){
System.out.println(resultSet1.getInt(3)+" "+
resultSet1.getNString(2)+" "+
resultSet1.getInt(1));
}
resultSet1.close();
preparedStatement.close();
resultSet.close();
connection.close();
}
}