This example issues a simple query and prints out the first column of each row using a Statement.
Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM mytable WHERE columnf = 500"); while (rs.next()) { System.out.print("Column 1 returned "); System.out.println(rs.getString(1)); } rs.close(); st.close();
This example issues the same query as before but uses a PreparedStatement and a bind value in the query.
int fvalue = 500; PreparedStatement st = conn.prepareStatement("SELECT * FROM mytable WHERE columnf = ?"); st.setInt(1, fvalue); ResultSet rs = st.executeQuery(); while (rs.next()) { System.out.print("Column 1 returned "); System.out.println(rs.getString(1)); } rs.close(); st.close();
The instance returns a ResultSet containing the results. Aster Database does not support cursor-based server-side caching of results that would save a small amount of time in parsing.
To retrieve data from the ResultSet instance, call next(), which returns true if there are results.
The ResultSet instance can be closed by calling close(), or if another query is issued using the same Statement instance that was used to create this ResultSet.
Statement stmt=con.createStatement(); ResultSet rs = stmt.executeQuery("select count(*) from page_views"); while (rs.next()) { System.out.println(rs.getInt(1)); } rs.close(); stmt.close();
You can also run Update/Insert/Delete statements and Create/Drop Table statements using the same method.