JDBC中的ResultSet的基本实现
package Jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class resultSet {
public static void main(String[] args) {
Connection co = null;
PreparedStatement p = null;
ResultSet r = null;
try {
Class.forName(“com.mysql.cj.jdbc.Driver”);
try {
co = DriverManager.getConnection("");
String sql = “select * from mzt_student where Sno>?”;
p = co.prepareStatement(sql);
p.setObject(1, 1000);
r = p.executeQuery();
while(r.next()) {
//getInt(1)1表示取出的第一列
System.out.println(r.getInt(1)+"----"+r.getString(2)+"----"+r.getString(3));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
r.close();
p.close();
co.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}