If your application is to run on databases from different vendors and you want some PreparedStatement objects to contain precompiled statements and others to contain uncompiled statements, proceed as follows:
When you access a Sybase database, make sure that the DYNAMIC_PREPARE connection property is set to true.
To return PreparedStatement objects containing precompiled statements, use Connection.prepareStatement( ) in the standard way:
PreparedStatement ps_precomp = Connection.prepareStatement(sql_string);
To return PreparedStatement objects containing uncompiled statements, use Connection.prepareCall( ).
Connection.prepareCall( ) returns a CallableStatement object, but since CallableStatement is a subclass of PreparedStatement, you can upcast a CallableStatement object to a PreparedStatement object, as in the following example:
PreparedStatement ps_uncomp = Connection.prepareCall(sql_string);
The PreparedStatement object ps_uncomp is guaranteed to contain an uncompiled statement, since only Connection.prepareStatement( ) is implemented to return PreparedStatement objects containing precompiled statements.
Copyright © 2003. Sybase Inc. All rights reserved. |
![]() |