If your application runs 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 because CallableStatement is a subclass of PreparedStatement, you can upcast a CallableStatement object to a PreparedStatement object, as follows:
PreparedStatement ps_uncomp = Connection.prepareCall(sql_string);
The PreparedStatement object ps_uncomp is guaranteed to contain an uncompiled statement, because only Connection.prepareStatement is implemented to return PreparedStatement objects containing precompiled statements.