views:

779

answers:

2

Hello,

I have a Java application that runs on Weblogic. The application needs to access a stored procedure in a DB2 data base, therefore a JDBC data source is configured and accessed by its JNDI name.

Data source:

ClassDriver: com.ibm.db2.jcc.DB2Driver

Properties:
user=MYUSER
DatabaseName=MYDB

The following example works as expected.

Context env = null;
DataSource pool = null;

Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://myserver:7777");

env = new InitialContext(ht);

pool = (DataSource) env.lookup("jdbc/myjndiname");
conn = pool.getConnection();

// call stored procedure with schema name
String procName = "MYSCHEMA.MYSTOREDPROCEDURE";
String sql = "CALL " + procName + "(?)";
callStmt = conn.prepareCall(sql);

callStmt.setString(1, "1");
callStmt.execute();

But now I need to call the stored procedure without the schema name and use a JDBC driver property instead.

Data source:

ClassDriver: com.ibm.db2.jcc.DB2Driver

Properties:
user=MYUSER
DatabaseName=MYDB
db2.jcc.override.currentSchema=MYSCHEMA
com.ibm.db2.jcc.DB2BaseDataSource.currentSchema=MYSCHEMA 

The following SQL call results in an error

// call stored procedure without schema name
String procName = "MYSTOREDPROCEDURE";
String sql = "CALL " + procName + "(?)";
callStmt = conn.prepareCall(sql);

SQL error:

SQLCODE = -440, ERROR:  NO PROCEDURE BY THE NAME MYSTOREDPROCEDURE HAVING
COMPATIBLE ARGUMENTS WAS FOUND IN THE CURRENT PATH 

I assume that the "currentSchema" properties are wrong.

Edit: It looks like I was wrong: the property currentSchema is not the problem! The SQL statement "select current_schema fromsysibm.sysdummy1" returns the correct schema (MYSCHEMA). The question is now, why "CALL MYSCHEMA.MYSTOREDPROCEDURE(?)" works and "CALL MYSTOREDPROCEDURE(?)" results in an error...

Any suggestions? Thanks!

A: 

You can at highest specify it in the JDBC URL of the datasource. E.g.

jdbc:db2://hostname:port/DBNAME:currentSchema=MYSCHEMA;

This however affects all connections coming from the same datasource.

BalusC
I tried your solution but still having the same problem. The driver (com.ibm.db2.jcc.DB2Driver) supports the property "currentSchema", right? Is any DB2 configuration needed to use the CURRENT SCHEMA special register?
Hellen
It may depend on the driver version used. I at least suppose that you're using the latest drivers. At least here are some docs which may be of use: http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.java.doc/doc/rjvdsprp.htm and http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.java.doc/doc/cjvcfgpr.htm
BalusC
It looks like i was wrong: the property is not the problem! The SQL statement "select current_schema fromsysibm.sysdummy1" returns the correct schema (MYSCHEMA). The question is now, why "CALL MYSCHEMA.MYSTOREDPROCEDURE(?)" works and "CALL MYSTOREDPROCEDURE(?)" results in an error...
Hellen
If your using db2 in an interactive mode, it uses the username as the default schema. In our case someone came up with the great idea that the schema should be db2admin. We use a different user to connect to the database, so we need to specify the schema in every operation.
Peter Schuetze
try the following Query to determine if it shows a different schema: select * from (values (CURRENT SCHEMA)) as X (R1)
Peter Schuetze
+2  A: 

Stored procedure (and function) resolution is not controlled by the CURRENT SCHEMA special register. It is controlled by the CURRENT PATH special register.

So, you can either:

  • Execute the SQL statement SET CURRENT PATH = MYSCHEMA
    or

  • Use the currentFunctionPath JDBC property.

Ian Bjorhovde
Property "currentFunctionPath" solved the problem. Thanks a lot!
Hellen