cancel
Showing results for 
Search instead for 
Did you mean: 

Native SQL

Former Member
0 Kudos

Hi,

How do you write Native SQL commands for a datasource whose SQL Engine type is Open SQL. For Eg: i have a datasource MyDS with SQL Engine type as Open SQL. For a connection "conn" to this datasource i cannot use methods like

conn.createStatement(int,int) as it is not supported by open sql.

Thanks in advance

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

i have gone thru the links tht u have mentioned. it requires some additional JARs for the same. Trying to find out wat JARs are reqd and where will i get it from ?

Former Member
0 Kudos
Former Member
Former Member
0 Kudos

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).

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);

. . .

}

And also see this link..

http://help.sap.com/saphelp_nw04/helpdata/en/bb/d604ad96d444bfa6cb15652d44b2a8/frameset.htm

Urs GS

Former Member
0 Kudos