SybConnection.PrepareStatement Method

Use the SybConnection.prepareStatement extension method to return dynamic SQL statements in PreparedStatement objects.

If your application allows jConnect-specific extensions to JDBC:
PreparedStatement SybConnection.prepareStatement(String sql_stmt, 
   boolean dynamic) throws SQLException

SybConnection.prepareStatement can return PreparedStatement objects containing either precompiled or uncompiled SQL statements, depending on the setting of the dynamic parameter. If dynamic is true, SybConnection.prepareStatement returns a PreparedStatement object with a precompiled SQL statement. If dynamic is false, it returns a PreparedStatement object with an uncompiled SQL statement.

This example shows the use of SybConnection.prepareStatement to return a PreparedStatement object containing a precompiled statement:
PreparedStatement precomp_stmt = ((SybConnection) conn).prepareStatement
   ("SELECT * FROM authors WHERE au_fname LIKE ?", true);

In this example, the connection object conn is cast to a SybConnection object to allow the use of SybConnection.prepareStatement. The SQL string passed to SybConnection.prepareStatement is precompiled in the database, even if the connection property DYNAMIC_PREPARE is false.

If the database generates an error because it cannot to precompile a statement sent to it through SybConnection.prepareStatement, jConnect throws a SQLException, and the call fails to return a PreparedStatement object. This is unlike Connection.prepareStatement, which traps SQL errors and, in the event of an error, returns a PreparedStatement object containing an uncompiled statement.