|
Mimer JDBC Engine 2.12 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--com.mimer.jdbc.Statement
A Statement object is used for executing a static SQL statement and
obtaining the results produced by it.
Only one ResultSet per Statement can be open at any point in time.
Therefore, if the reading of one ResultSet is interleaved with the reading
of another, each must have been generated by different Statements.
All statement execute methods implicitly close a statements current
ResultSet if an open one exists.
With a few exceptions Statement objects supports all Mimer SQL constructs introduced
up until the driver was released. When the driver is older than the server, there is
no guarantee that new SQL constructs will work with the driver.
The below Mimer SQL constructs are not supported by the JDBC driver, and also why they aren't supported.
| SQL statement | Explanation |
|---|---|
SET TRANSACTION START EXPLICIT |
In JDBC transactions are always started automatically when the first statement of a transaction is executed. There is no need to set the transaction in implicit start mode. |
START |
Since transactions are automatically started when the first statement is executed, there is no need to explicitly start them. |
ROLLBACK |
In JDBC transactions are managed using the JDBC interface. Use the methods Connection.rollback and Connection.commit instead. |
SET TRANSACTION READ WRITE |
Use the JDBC method Connection.setReadOnly instead. |
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED |
Use the JDBC method Connection.setTransactionIsolation instead. |
| Field Summary |
| Fields inherited from interface java.sql.Statement |
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO |
| Method Summary | |
void |
addBatch(String sql)
Adds an SQL-statement to the batch. |
void |
cancel()
Requests to cancel the currently executing statement. |
void |
clearBatch()
Clears the current batch. |
void |
clearStatement()
Clear attributes in this statement object. |
void |
clearWarnings()
Clears all warnings reported on the object. |
void |
close()
Closes the statement. |
boolean |
execute(String parm1)
Executes any SQL query or statement. |
int[] |
executeBatch()
Executing the current batch. |
ResultSet |
executeQuery(String sql)
Executes a query that returns a result set. |
int |
executeUpdate(String sql)
Executes an SQL-statement that don't return a result set. |
Connection |
getConnection()
Returns the Connection object related to this Statement. |
int |
getFetchDirection()
Gets the current fetch direction hint. |
int |
getFetchSize()
Retrieves the current fetch size. |
int |
getMaxFieldSize()
Gets the max field size. |
int |
getMaxRows()
Getting the maximum number of rows to be returned in a result set. |
boolean |
getMoreResults()
Check if there are moew result sets open on this statement. |
int |
getQueryTimeout()
Gets the query timeout in seconds. |
ResultSet |
getResultSet()
Returns the result set created by the last statement. |
int |
getResultSetConcurrency()
Gets the current result set concurrency. |
int |
getResultSetType()
Gets the current result set type. |
int |
getUpdateCount()
Returns the number of rows updated by the last statement. |
SQLWarning |
getWarnings()
Returns the first warning posted to this object. |
void |
setCursorName(String name)
Sets the cursor name of the statement. |
void |
setEscapeProcessing(boolean enable)
Enable or disables SQL escape clause processing. |
void |
setFetchDirection(int direction)
Sets the current fetch direction hint. |
void |
setFetchSize(int rows)
Sets the current fetch size. |
void |
setMaxFieldSize(int max)
Sets the max field size. |
void |
setMaxRows(int max)
Setting the maximum number of rows to be returned in a result set. |
void |
setQueryTimeout(int timeout)
Sets the query timeout in seconds. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.sql.Statement |
execute, execute, execute, executeUpdate, executeUpdate, executeUpdate, getGeneratedKeys, getMoreResults, getResultSetHoldability |
| Method Detail |
public void addBatch(String sql)
throws SQLException
Performance considerations: Batching several SQL-statements in one batch can have a tremendous effect on performance. A batch is transferred to the server in one network call. Executing the same statements one by one most probably involve one request and one return packet. Batching 10 statements both saves transmission times as well as server communications.
A word of caution. If many semantically identical SQL-statements are to be executing, but with
different data, better execution times and scalability will be experienced by using a batched
PreparedStatement instead. One should avoid batching Statement like below:
Statement stmt = con.createStatement();
stmt.addBatch("insert into OURTAB values (1,'First man')");
stmt.addBatch("insert into OURTAB values (2,'Second man')");
stmt.addBatch("insert into OURTAB values (3,'Third man')");
stmt.addBatch("insert into OURTAB values (4,'Fourth man')");
stmt.addBatch("insert into OURTAB values (5,'Fifth man')");
stmt.executeBatch();
Instead, use a PreparedStatement:
PreparedStatement pstmt = con.prepareStatement("insert into OURTAB values (?,?)");
pstmt.setInt(1,1);
pstmt.setString(1,"First man");
pstmt.addBatch();
pstmt.setInt(1,2);
pstmt.setString(1,"Second man");
pstmt.addBatch();
pstmt.setInt(1,3);
pstmt.setString(1,"Third man");
pstmt.addBatch();
pstmt.setInt(1,4);
pstmt.setString(1,"Fourth man");
pstmt.addBatch();
pstmt.setInt(1,5);
pstmt.setString(1,"Fifth man");
pstmt.addBatch();
pstmt.executeBatch();
addBatch in interface Statementsql - The SQL statement to batch.
SQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown.executeBatch()
public void cancel()
throws SQLException
Whenever this method is called, the client sends a cancel request to the server. Once the request is transmitted, control is returned to the caller. Therefore, the client doesn't know that the server for sure has cancelled the operation. The actual cancellation can take some time depending on load and what the server is doing. In most cases, however, the cancellation should be instantaneous.
This method should be called from a separate thread. The thread that started the operation to be cancelled is waiting for the server to complete its work. Once the operation is cancelled, SQLSTATE S1008 is thrown in the thread that initiated the work.
cancel in interface StatementSQLException - if an error occurs. HY010 is thrown if the statement is not open.
public void clearBatch()
throws SQLException
clearBatch in interface StatementSQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown.addBatch(java.lang.String),
executeBatch()
public void clearStatement()
throws SQLException
Clear all warnings. Close the current result set if there is one.
SQLException - when the statement is closed
public void clearWarnings()
throws SQLException
clearWarnings in interface StatementSQLException - if an error occurs.
public void close()
throws SQLException
close in interface StatementSQLException - if an error occurs.
public boolean execute(String parm1)
throws SQLException
execute in interface StatementStatement.getResultSet to obtain the ResultSet object.
SQLException - if an error occurs. HY010 is thrown if the statement is not open. HY000 is thrown if the statement contains parameter markers, in this case you must use a PreparedStatement object instead. HY000 may also be thrown when the SQL statement was not supported by the driver, see Statement for an overview on which statements that are not supported and why. 42000 is thrown if the SQL contained a syntax error. 34000 is thrown if a UPDATE/DELETE WHERE CURRENT OF specified a cursor that doesn't exist. S1008 is thrown if the execution is cancelled.executeUpdate(java.lang.String),
executeQuery(java.lang.String),
getResultSet()
public int[] executeBatch()
throws SQLException
executeBatch in interface StatementSQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown. This call may execute a lot
of server side code and may return any server runtime error. S1008 is thrown if the execution is cancelled.addBatch(java.lang.String)
public ResultSet executeQuery(String sql)
throws SQLException
executeQuery in interface Statementsql - The SQL query.
SQLException - if an error occurs. HY010 is thrown if the statement is not open. HY000 is thrown if the statement contains parameter markers, in this case you must use a PreparedStatement object instead. HY000 may also be thrown when the SQL statement was not supported by the driver, see Statement for an overview on which statements that are not supported and why. 42000 is thrown if the SQL contained a syntax error or the statement wasn't a query. 34000 is thrown if a UPDATE/DELETE WHERE CURRENT OF specified a cursor that doesn't exist. S1008 is thrown if the execution is cancelled.executeUpdate(java.lang.String),
execute(java.lang.String)
public int executeUpdate(String sql)
throws SQLException
executeUpdate in interface Statementsql - The SQL-statement.
SQLException - if an error occurs. HY010 is thrown if the statement is not open. HY000 is thrown if the statement contains parameter markers, in this case you must use a PreparedStatement object instead. HY000 may also be thrown when the SQL statement was not supported by the driver, see Statement for an overview on which statements that are not supported and why. 42000 is thrown if the SQL contained a syntax error or the statement was a query. 34000 is thrown if a UPDATE/DELETE WHERE CURRENT OF specified a cursor that doesn't exist. S1008 is thrown if the execution is cancelled.executeQuery(java.lang.String),
execute(java.lang.String)
public Connection getConnection()
throws SQLException
Connection object related to this Statement.
getConnection in interface StatementSQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown.
public int getFetchDirection()
throws SQLException
getFetchDirection in interface StatementSQLException - if an error occurs.setFetchDirection(int)
public int getFetchSize()
throws SQLException
getFetchSize in interface StatementSQLException - if an error occurs.setFetchSize(int)
public int getMaxFieldSize()
throws SQLException
getMaxFieldSize in interface StatementSQLException - if an error occurs. HY010 is thrown if the statement is not open.setMaxFieldSize(int)
public int getMaxRows()
throws SQLException
getMaxRows in interface StatementSQLException - if an error occurs. HY010 is thrown if the statement is not open.setMaxRows(int)
public boolean getMoreResults()
throws SQLException
Mimer SQL procedures may only return one result set. This call will therefore always return false. But since this method is supposed to abandon the current result set and move on to the next, any open result set is closed.
getMoreResults in interface StatementSQLException - if an error occurred. HY010 if the statement is closed.
public int getQueryTimeout()
throws SQLException
getQueryTimeout in interface StatementSQLException - if an error occurred. HY010 if the statement is closed.setQueryTimeout(int)
public ResultSet getResultSet()
throws SQLException
getResultSet in interface StatementSQLException - if an error occurs. SQLSTATE HY010 is thrown if the statement is not open.
public int getResultSetConcurrency()
throws SQLException
getResultSetConcurrency in interface StatementSQLException - if an error occurs.Connection.createStatement(int,int),
Connection.prepareStatement(String,int,int),
Connection.prepareCall(String,int,int)
public int getResultSetType()
throws SQLException
getResultSetType in interface StatementSQLException - if an error occurs.Connection.createStatement(int,int),
Connection.prepareStatement(String,int,int),
Connection.prepareCall(String,int,int)
public int getUpdateCount()
throws SQLException
getUpdateCount in interface StatementSQLException - if an error occurs. SQLSTATE HY010 is thrown if the statement is not open.
public SQLWarning getWarnings()
throws SQLException
getWarnings in interface StatementSQLException - if an error occurred.clearWarnings()
public void setCursorName(String name)
throws SQLException
In Mimer, cursor names may be used by other statements to refer to this statement. For example, the first statement creates an updatable result set. A second statement issues UPDATE WHERE CURRENT OF statements to update rows in the result set.
For example, see this pseudocode:
Statement stmt1 = con.createStatement();
stmt1.setCursorName("CURSOR1");
Statement stmt2 = con.createStatement();
ResultSet rs = stmt1.executeQuery("select COLUMN1,COLUMN2 from TABLE1");
rs.next();
...
...
stmt2.execute("update TABLE1 set COLUMN1 = 'new value' where current of CURSOR1");
See the Mimer SQL Reference manual for more information about UPDATE WHERE CURRENT OF statements.
setCursorName in interface Statementname - The new cursor name.
SQLException - if an error occurs. SQLSTATE HY010 is thrown if the statement is not open.
NullException - if name was null.
public void setEscapeProcessing(boolean enable)
throws SQLException
The escape clauses are expanded by a preprocessor before feeding the statement to the SQL compiler. Performance can be slightly improved if this option is turned off.
setEscapeProcessing in interface Statementenable - True if escape processing should be executed.
SQLException - if an error occurs. SQLSTATE HY010 is thrown if the statement is not open.Connection.nativeSQL(java.lang.String)
public void setFetchDirection(int direction)
throws SQLException
Mimer JDBC uses this information to guess which row to be fetched next. The rows most likely to be be fetched next are prefetched. If the fetch direction is FETCH_FORWARD, the prefetch will mostly contain rows after the cursor. If the fetch direction is FETCH_REVERSE, the prefetch will mostly contain rows before the cursor.
This setting affects all subsequently created result sets.
setFetchDirection in interface Statementdirection - The fetch direction hint.
SQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown. If the fetch direction is illegal HY024 is thrown.getFetchDirection()
public void setFetchSize(int rows)
throws SQLException
The JDBC driver prefetches data whenever this is suitable. This means that on the first ResultSet.next()
call of a result set, 1000 rows may be fetched and stored in the client. Setting this attribute gives the
application programmer means to control the amount of rows fetched.
The default fetch size is always selected to be something appropriate depending on the environment. A Mimer JDBC Engine client mostly selects a fetch size which will contain about 60 kb of data.
Performance consideration: Most of the time, the default fetch size is good enough for us. There are some situations where a small fetch size is suitable.
The fetch size is different from max rows in the following aspects.
setFetchSize in interface Statementrows - The fetch size.
SQLException - if an error occurs. If the Statement object is closed, SQLSTATE HY010 is thrown. HY024 is thrown if the fetch size is negative.setMaxRows(int),
getFetchSize()
public void setMaxFieldSize(int max)
throws SQLException
setMaxFieldSize in interface Statementmax - The new max field size.
SQLException - if an error occurs. SQLSTATE HY024 is thrown of the parameter was negative. HY010 is thrown if the statement is not open.
public void setMaxRows(int max)
throws SQLException
Limiting the number of rows in a result set is useful when the JDBC programmer knows for sure that he is only interested in the first n rows. Some advantages are:
This setting affects all subsequently created reesult set.
setMaxRows in interface Statementmax - The new max rows value.
SQLException - if an error occurs. SQLSTATE HY024 is thrown if the max parameter is negative. HY010 is thrown if the statement is not open.setFetchSize(int)
public void setQueryTimeout(int timeout)
throws SQLException
setQueryTimeout in interface Statementtimeout - The timeout in seconds. 0 for no timeout.
SQLException - if an error occurred. SQLSTATE HY024 for an illegal timeout value. HY010 if the statement is closed.getQueryTimeout()
|
Mimer JDBC Engine 2.12 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||