handled by the ResultSet class. For now, just note that it can handle both in-memory results (in the form of a Hashtable) and results read directly from the data file. Statement The Statement class contains methods to execute SQL statements directly against the database and to obtain the results. A Statement object is created using the createStatement method from the Connection object. Of note in Listing 10.21 are the three methods used to execute SQL statements: executeUpdate, executeQuery, and execute. In actuality, you only need to worry about implementing the execute method; the other methods use it to perform their work. In fact, the code provided in the SimpleText driver should be identical for all JDBC drivers. Listing 10.21 Executing SQL statements. //———————————————————————- — // executeQuery - JDBC API // Execute an SQL statement that returns a single ResultSet. // // sql Typically this is a static SQL SELECT statement. // // Returns the table of data produced by the SQL statement. //———————————————————————- — public ResultSet executeQuery( String sql) throws SQLException { if (traceOn()) { trace(”@executeQuery(” + sql + “)”); } java.sql.ResultSet rs = null; // Execute the query. If execute returns true, then a result set // exists. if (execute(sql)) { rs = getResultSet(); } else { // If the statement does not create a ResultSet, the // specification indicates that an SQLException should // be raised. throw new SQLException(”Statement did not create a ResultSet”); } return rs; } //———————————————————————- — // executeUpdate - JDBC API // Execute an SQL INSERT, UPDATE, or DELETE statement. In addition, // SQL statements that return nothing, such as SQL DDL statements, // can be executed.
Get account with us and you will get completely access to our free web templates database with over 10.000 templates in it to build your website.Don’t wait, go and check free web templates.

Leave a Reply