ResultSet 兩種取值 按順序總是用的也總是 忘記 第一個是1開始 做個記錄
阿新 • • 發佈:2019-02-01
您指定欄位名稱來取得資料:
ResultSet result = stmt.executeQuery("SELECT * FROM message");
while(result.next()) ...{
System.out.print(result.getString("name") + " ");
System.out.print(result.getString("email") + " ");
System.out.print(result.getString("subject") + " ");
System.out.print(result.getString("time") + " ");
System.out.println(result.getString("memo") + " ");
}
使用查詢到的結果之欄位順序來顯示結果的方式如下:
ResultSet result = stmt.executeQuery("SELECT * FROM message");
while(result.next()) ...{
System.out.print(result.getString(1) + " ");
System.out.print(result.getString(2) + " ");
System.out.print(result.getString(3) + " ");
System.out.print(result.getString(4) + " ");
System.out.println(result.getString(5) + " ");
}
ResultSet result = stmt.executeQuery("SELECT * FROM message");
while(result.next()) ...{
System.out.print(result.getString("name") + " ");
System.out.print(result.getString("email") + " ");
System.out.print(result.getString("subject") + " ");
System.out.print(result.getString("time") + " ");
System.out.println(result.getString("memo") + " ");
}
使用查詢到的結果之欄位順序來顯示結果的方式如下:
ResultSet result = stmt.executeQuery("SELECT * FROM message");
while(result.next()) ...{
System.out.print(result.getString(1) + " ");
System.out.print(result.getString(2) + " ");
System.out.print(result.getString(3) + " ");
System.out.print(result.getString(4) + " ");
System.out.println(result.getString(5) + " ");
}