-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 に答える