Java的JDBC的ResultSet的简单理解
import java.sql.*;
public class JDBC06{
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql:///hsp_db02","root","011012");
String sql="select * from account";
Statement stm=con.createStatement();
ResultSet rs =stm.executeQuery(sql);
rs.next();
int id=rs.getInt(1);
String name=rs.getString("name");
double balance=rs.getDouble(3);
System.out.println(id+"----"+name+"----"+balance);
stm.close();
con.close();
}
}
|