問い合わせの発行、及び、結果の処理

Any time you want to issue SQL statements to the database, you require a Statement instance. Once you have a Statement, you can use the executeQuery() method to issue a query. This will return a ResultSet instance, which contains the entire result.

SQL 文をデータベースに発行する時には必ず、Statement インスタンス が必要です。Statement インスタンスを持っていれば、executeQuery() メソッドを使って問い合わせを発行できます。このメソッドは、結果全 体を持った ResultSet インスタンスを返します。

Statement インタフェースの使用

The following must be considered when using the Statement interface:

Statement インタフェースを使用する際に以下を考慮しなければなりま せん。

ResultSet インタフェースの使用

The following must be considered when using the ResultSet interface:

ResultSet インタフェースを使用する際、以下のことを考慮しなければな りません。

An example is as follows:

例を以下に示します。

Statement st = db.createStatement();
ResultSet rs = st.executeQuery("select * from mytable");
while(rs.next()) {
    System.out.print("Column 1 returned ");
    System.out.println(rs.getString(1));
}
rs.close();
st.close();