我想从一个表中获取personID并将其用于第二个表中,并且从第二个表中打印每个列值 ,但是我收到了错误column index out of range, 3 < 1
。订单表由3列组成。结果集开始之前的MySQL
public void getPersonsOrders(String firstName){
Connection con = connect();
try{
Statement s = con.createStatement();
s.executeUpdate("use stl;");
ResultSet rs1 = s.executeQuery("select personID from person where first_name = " +"'"+firstName+"'"+";"); //get persons ID no.
rs1.next();
ResultSet rs2 = s.executeQuery("select * from orderr where personID = "+rs1.getInt(3)+";"); //use ID no. to
for(int i = 1; i < 4; i++){ //retrive order
System.out.println(rs2.getInt(i));
}
}
catch(SQLException e){
System.out.println("3" +e.getMessage());
}
}
'rs1.getInt(3)' - 'rs1'中只有一列(索引为1) –
查看SQL JOIN – everton