我想從一個表中獲取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