-1

仅在从 rs.getString 1 选择结果后,我该怎么做才能在下一行显示 rs.getString2 ?

Statement statement = con.createStatement();
     ResultSet rs = statement.executeQuery("select * from state");
     while ( rs.next() ){
       System.out.println(rs.getString(1) + " " +rs.getString(2)); 
4

1 回答 1

0
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("select * from state");
while ( rs.next() ){
    StringBuilder br = new StringBuilder();
    br.append(rs.getString(1)); //print the column 1 in the current row
    br.append(" "); //add space
    rs.next(); //move to the next row
    br.append(rs.getString(2)); //print the column 2 in the next row
    rs.previous(); //go back to the current row of this current iteration
    System.out.println(br.toString()); //print
}
于 2013-04-14T07:25:25.563 回答