com.sap.sql
Class NativeSQLAccess

java.lang.Object
  |
  +--com.sap.sql.NativeSQLAccess

public class NativeSQLAccess
extends java.lang.Object

This class allows to circumvent Open SQL restrictions on specific databaseses. It makes it possible to prepare and execute Native SQL statements on an Open SQL connection. Additionally it offers methods to determine the database vendor underlying an Open SQL conncetion.


Field Summary
static int VENDOR_DB2_UDB
          The constant that is used to identify a DB2 UDB for UNIX and NT database product.
static int VENDOR_DB2_UDB_AS400
          The constant that is used to identify a DB2 UDB for AS/400 database product.
static int VENDOR_DB2_UDB_OS390
          The constant that is used to identify a DB2 UDB for OS/390 database product.
static int VENDOR_INFORMIX
          The constant that is used to identify an Informix database product.
static int VENDOR_MS_SQL_SERVER
          The constant that is used to identify a MS SQL Server database product.
static int VENDOR_ORACLE
          The constant that is used to identify an Oracle database product.
static int VENDOR_SAPDB
          The constant that is used to identify a SAP DB database product.
static int VENDOR_UNKNOWN
          The constant that is used to identify an unknown database product.
 
Method Summary
static java.sql.Statement createNativeStatement(java.sql.Connection connection)
          This method allows to create a Statement object on the Native SQL connection underlying a given Open SQL connection.
static java.sql.Statement createNativeStatement(java.sql.Connection connection, int resultSetType, int resultSetConcurrency)
          This method allows to create a Statement object on the Native SQL connection underlying a given Open SQL connection.
static java.sql.DatabaseMetaData getNativeMetaData(java.sql.Connection connection)
          This method gives access to the DatabaseMetaData of the Native SQL connection underlying an Open SQL connection.
static int getVendorID(java.sql.Connection connection)
          Gets the product identifier VENDOR_<vendor name> for the given connection.
static int getVendorID(java.lang.String productName)
          Gets the product identifier VENDOR_<vendor name> that corresponds to the given database product name.
static java.lang.String getVendorName(java.sql.Connection connection)
          Gets the corresponding database product name for the given database connection.
static java.lang.String getVendorName(int vendorID)
          Gets the database product name that corresponds to the given product identifier.
static java.lang.String[] getVendorNames()
          Gets an array of all supported database product names.
static java.lang.String getVendorTitle(int vendorID)
          Gets the database product title for the given product identifier.
static boolean isTransientSQLError(java.sql.Connection connection, java.sql.SQLException exception)
          Returns true, if the SQLException originates from a database error that is of transient nature, false otherwise.
static java.sql.CallableStatement prepareNativeCall(java.sql.Connection connection, java.lang.String sql)
          This method allows to prepare a CallableStatement object on the Native SQL connection underlying a given Open SQL connection.
static java.sql.CallableStatement prepareNativeCall(java.sql.Connection connection, java.lang.String sql, int resultSetType, int resultSetConcurrency)
          This method allows to prepare a CallableStatement object on the Native SQL connection underlying a given Open SQL connection.
static java.sql.PreparedStatement prepareNativeStatement(java.sql.Connection connection, java.lang.String sql)
          This method allows to prepare a PreparedStatement object on the Native SQL connection underlying a given Open SQL connection.
static java.sql.PreparedStatement prepareNativeStatement(java.sql.Connection connection, java.lang.String sql, int resultSetType, int resultSetConcurrency)
          This method allows to prepare a PreparedStatement object on the Native SQL connection underlying a given Open SQL connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VENDOR_UNKNOWN

public static final int VENDOR_UNKNOWN
The constant that is used to identify an unknown database product.

VENDOR_DB2_UDB

public static final int VENDOR_DB2_UDB
The constant that is used to identify a DB2 UDB for UNIX and NT database product.

VENDOR_DB2_UDB_AS400

public static final int VENDOR_DB2_UDB_AS400
The constant that is used to identify a DB2 UDB for AS/400 database product.

VENDOR_DB2_UDB_OS390

public static final int VENDOR_DB2_UDB_OS390
The constant that is used to identify a DB2 UDB for OS/390 database product.

VENDOR_INFORMIX

public static final int VENDOR_INFORMIX
The constant that is used to identify an Informix database product.

VENDOR_MS_SQL_SERVER

public static final int VENDOR_MS_SQL_SERVER
The constant that is used to identify a MS SQL Server database product.

VENDOR_ORACLE

public static final int VENDOR_ORACLE
The constant that is used to identify an Oracle database product.

VENDOR_SAPDB

public static final int VENDOR_SAPDB
The constant that is used to identify a SAP DB database product.
Method Detail

getNativeMetaData

public static java.sql.DatabaseMetaData getNativeMetaData(java.sql.Connection connection)
                                                   throws java.sql.SQLException
This method gives access to the DatabaseMetaData of the Native SQL connection underlying an Open SQL connection.
Parameters:
connection - a database connection
Returns:
a DatabaseMetaData object for the Native SQL connection underlying the given connection connection
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.getMetaData()

createNativeStatement

public static java.sql.Statement createNativeStatement(java.sql.Connection connection)
                                                throws java.sql.SQLException
This method allows to create a Statement object on the Native SQL connection underlying a given Open SQL connection. It works just like the createStatement() method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
Returns:
a Statement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.createStatement()

createNativeStatement

public static java.sql.Statement createNativeStatement(java.sql.Connection connection,
                                                       int resultSetType,
                                                       int resultSetConcurrency)
                                                throws java.sql.SQLException
This method allows to create a Statement object on the Native SQL connection underlying a given Open SQL connection. It works just like the createStatement(int, int) method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
resultSetType - a result set type; see java.sql.ResultSet.TYPE_XXX
resultSetConcurrency - a concurrency type; see java.sql.ResultSet.CONCUR_XXX
Returns:
a Statement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.createStatement(int, int)

prepareNativeStatement

public static java.sql.PreparedStatement prepareNativeStatement(java.sql.Connection connection,
                                                                java.lang.String sql)
                                                         throws java.sql.SQLException
This method allows to prepare a PreparedStatement object on the Native SQL connection underlying a given Open SQL connection. It works just like the prepareStatement(String) method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
sql - the SQL statement to be prepared
Returns:
a PreparedStatement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.prepareStatement(String)

prepareNativeStatement

public static java.sql.PreparedStatement prepareNativeStatement(java.sql.Connection connection,
                                                                java.lang.String sql,
                                                                int resultSetType,
                                                                int resultSetConcurrency)
                                                         throws java.sql.SQLException
This method allows to prepare a PreparedStatement object on the Native SQL connection underlying a given Open SQL connection. It works just like the prepareStatement(String, int, int) method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
sql - the SQL statement to be prepared
resultSetType - a result set type; see java.sql.ResultSet.TYPE_XXX
resultSetConcurrency - a concurrency type; see java.sql.ResultSet.CONCUR_XXX
Returns:
a PreparedStatement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.prepareStatement(String, int, int)

prepareNativeCall

public static java.sql.CallableStatement prepareNativeCall(java.sql.Connection connection,
                                                           java.lang.String sql)
                                                    throws java.sql.SQLException
This method allows to prepare a CallableStatement object on the Native SQL connection underlying a given Open SQL connection. It works just like the prepareCall(String) method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
sql - the SQL statement to be prepared
Returns:
a CallableStatement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.prepareCall(String)

prepareNativeCall

public static java.sql.CallableStatement prepareNativeCall(java.sql.Connection connection,
                                                           java.lang.String sql,
                                                           int resultSetType,
                                                           int resultSetConcurrency)
                                                    throws java.sql.SQLException
This method allows to prepare a CallableStatement object on the Native SQL connection underlying a given Open SQL connection. It works just like the prepareCall(String, int, int) method on the underlying Native SQL connection.

This allows to circumvent the compliance check with Open SQL and might be used to exploit database specific SQL that doesn't obey to the Open SQL subset.

Parameters:
connection - a database connection
sql - the SQL statement to be prepared
resultSetType - a result set type; see java.sql.ResultSet.TYPE_XXX
resultSetConcurrency - a concurrency type; see java.sql.ResultSet.CONCUR_XXX
Returns:
a CallableStatement object for the Native SQL connection underlying the given connection connection.
Throws:
java.sql.SQLException - if a database error occurs
See Also:
Connection.prepareCall(String, int, int)

getVendorID

public static int getVendorID(java.lang.String productName)
Gets the product identifier VENDOR_<vendor name> that corresponds to the given database product name.

The method returns VENDOR_UNKNOWN if the given database product name is unknown.

Parameters:
productName - a database product name
Returns:
the corresponding product identifier VENDOR_<vendor name>

getVendorID

public static int getVendorID(java.sql.Connection connection)
Gets the product identifier VENDOR_<vendor name> for the given connection.

The method returns VENDOR_UNKNOWN if the database product couldn't be determined for the given connection.

Parameters:
connection - a database connection
Returns:
the corresponding database product identifier VENDOR_<vendor name>

getVendorName

public static java.lang.String getVendorName(int vendorID)
Gets the database product name that corresponds to the given product identifier.

The method returns the String "VENDOR_UNKNOWN" if the given product identifier doesn't match with one of the defined product identifiers VENDOR_<vendor name>.

Parameters:
vendorID - a database product identifier
Returns:
the corresponding database product name

getVendorName

public static java.lang.String getVendorName(java.sql.Connection connection)
Gets the corresponding database product name for the given database connection.

The method returns the String "VENDOR_UNKNOWN" if the database product couldn't be determined for the given connection.

Parameters:
connection - a database connection
Returns:
the corresponding database product name

getVendorNames

public static java.lang.String[] getVendorNames()
Gets an array of all supported database product names.

Returns:
an array of supported database product names

getVendorTitle

public static java.lang.String getVendorTitle(int vendorID)
Gets the database product title for the given product identifier. The product title is guaranteed to be at most 30 characters in length. Callers must not depend on the title's content and formatting.

An empty string is returned if no title could be determined.

Parameters:
vendorID - a database product identifier.
Returns:
the corresponding database product title, or the empty string.

isTransientSQLError

public static boolean isTransientSQLError(java.sql.Connection connection,
                                          java.sql.SQLException exception)
                                   throws java.sql.SQLException
Returns true, if the SQLException originates from a database error that is of transient nature, false otherwise. Transient error means that, with some likelihood, the error will disappear if the failing transaction is re-executed. The current implementation only considers deadlocks as transient errors. On database platforms that do not have a clear-cut deadlock detection mechanism a timeout error may occur in a deadlock situation, instead. Hence, the method also returns TRUE in case of a timeout error on a database platform without deadlock detection.

Database systems do not have identical transactional behaviour in case of transient errors. Some database management systems roll back the complete transaction after timeout or deadlock errors, some database systems roll back the affected SQL statement only.This leads to the programming paradigm: In case of a transient error, it is not possible to re-execute the single statement that caused the error. The complete transaction has to be rolled back and, if desired, repeated.

Parameters:
connection - the database connection on which the exception occurred.
exception - the SQL exception that is to be analysed.
Returns:
true, if the SQLException originates from a database error that is of transient nature.
Throws:
java.sql.SQLException - if an error occurs