Show TOC Start of Content Area

Function documentation Native SQL Access  Locate the document in its SAP Library structure

Use

In exceptional cases it may be necessary to program non-portable SQL statements that exceed the scope of the Open SQL/JDBC language. For this purpose, the help class com.sap.sql.NativeSQLAccess is provided.

Features

Using the static method NativeSQLAccess.getVendorID(Connection conn), you can determine the underlying database vendor. You use this method to ensure that a non-portable SQL statement is issued on the corresponding database platform only.

The NativeSQLAccess class offers three options for issuing a non-portable SQL statement:

      NativeSQLAccess.createNativeStatement() – generates an object of the class java.sql.Statement.

      NativeSQLAccess.prepareNativeStatement() – generates an object of the class java.sql.PreparedStatement.

      NativeSQLAccess.prepareNativeCall() – generates an object of the class java.sql.CallableStatement (a Stored Procedure is called).

The following code snippet is an example of database-specific coding (where conn is a database connection object that already exists):

Example

import java.sql.PreparedStatement;

import com.sap.sql.NativeSQLAccess;

 

String mssOnlyStmt = "…";

// ensure correct process environment

if (NativeSQLAccess.getVendorID(conn) !=

   NativeSQLAccess.VENDOR_MS_SQL_SERVER) {

// error handling

} else {

// variant 1

   PreparedStatement ps =

   NativeSQLAccess.prepareNativeStatement(

      conn, mssOnlyStmt);

   . . .

// variant 2

   Statement stmt =

      NativeSQLAccess.createNativeStatement(conn);

   int result = stmt.execute(mssOnlyStmt);

   . . .

// variant 3

   CallableStatement cs =

      NativeSQLAccess.prepareNativeCall(

         conn, mssOnlyStmt);

   . . .

}

 

End of Content Area