cancel
Showing results for 
Search instead for 
Did you mean: 

Problems opening database connection

Former Member
0 Kudos

Hello,

In trying to open a database connection, I am using the following code:

Connection conn = null;

Context ctx = null;

try

{

ctx = new InitialContext(env);

Object obj = (Object)ctx.lookup("jdbc/SAPJ2EDB");

DataSource ds = (DataSource)PortableRemoteObject.narrow(obj, DataSource.class);

conn = ds.getConnection();

...

}

when I call ds.getConnection(), I get the following exception:

com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: com.sap.sql.log.OpenSQLException: Could not instantiate class com.sap.sql.connect.OpenSQLDataSourceImpl.

at com.sap.engine.services.dbpool.cci.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:59)

at com.hubbell.portal.masterminder.material.persistence.MaterialPersistor.persist(MaterialPersistor.java:46)

at com.hubbell.portal.masterminder.material.persistence.MaterialPersistorTest.testPersistor(MaterialPersistorTest.java:36)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at junit.framework.TestCase.runTest(TestCase.java:154)

at junit.framework.TestCase.runBare(TestCase.java:127)

at junit.framework.TestResult$1.protect(TestResult.java:106)

at junit.framework.TestResult.runProtected(TestResult.java:124)

at junit.framework.TestResult.run(TestResult.java:109)

at junit.framework.TestCase.run(TestCase.java:118)

at junit.framework.TestSuite.runTest(TestSuite.java:208)

at junit.framework.TestSuite.run(TestSuite.java:203)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

Caused by: com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: com.sap.sql.log.OpenSQLException: Could not instantiate class com.sap.sql.connect.OpenSQLDataSourceImpl.

at com.sap.engine.services.dbpool.spi.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:188)

at com.sap.engine.services.dbpool.spi.DefaultConnectionManagerImpl.allocateConnection(DefaultConnectionManagerImpl.java:26)

at com.sap.engine.services.dbpool.cci.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:51)

... 17 more

Caused by: com.sap.sql.log.OpenSQLException: Could not instantiate class com.sap.sql.connect.OpenSQLDataSourceImpl.

at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:106)

at com.sap.sql.connect.OpenSQLDataSource.newInstance(OpenSQLDataSource.java:153)

at com.sap.sql.connect.OpenSQLDataSource.newInstance(OpenSQLDataSource.java:133)

at com.sap.engine.services.dbpool.spi.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:102)

... 19 more

Caused by: com.sap.sql.log.OpenSQLException: Could not instantiate class com.sap.sql.connect.CommonFactoryLib.

at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:106)

at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:145)

at com.sap.sql.connect.OpenSQLDataSourceImpl.<init>(OpenSQLDataSourceImpl.java:128)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at com.sap.sql.connect.OpenSQLDataSource.newInstance(OpenSQLDataSource.java:148)

... 21 more

Caused by: java.lang.ClassNotFoundException: com.sap.sql.connect.CommonFactoryLib

at java.net.URLClassLoader$1.run(URLClassLoader.java:199)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:141)

at com.sap.sql.connect.OpenSQLDataSourceImpl.<init>(OpenSQLDataSourceImpl.java:121)

... 28 more

error code: 0

SQLState: 08003

I have the opensqlcore.jar file included in my project's build path so I dont understand why the class loader is having trouble loading CommonFactory.class or OpenSqlDataSourceImpl.class .

Thanks,

JC

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi jason,

Try out this following code

Initialcontext ctx = new Initialcontext();

DataSource ds=(DataSource)ctx.lookup(jdbc/sapj2edb);

Connection con=ds.getConnection();

Don forget to add the classes12.jar inside the java build path bcoz this throws u some exceptions.

Thanks,

Nagarajan.

Vlado
Advisor
Advisor
0 Kudos

Hi Jason,

opensqlsta.jar contains all those classes related to OpenSQL, so you should include it in your classpath instead of opensqlcore.jar.

HTH,

Vladimir

Former Member
0 Kudos

Hi,

Ok...I'm getting closer, but I'm not quite there yet.

I've got the following error now:

Caused by: com.sap.security.core.server.secstorefs.FileMissingException: File "SecStore.properties" does not exist although it should.

at com.sap.security.core.server.secstorefs.StorageHandler.openExistingStore(StorageHandler.java:372)

at com.sap.security.core.server.secstorefs.SecStoreFS.openExistingStore(SecStoreFS.java:1946)

at com.sap.sql.connect.OpenSQLConnectInfo.getStore(OpenSQLConnectInfo.java:806)

at com.sap.sql.connect.OpenSQLConnectInfo.lookup(OpenSQLConnectInfo.java:787)

at com.sap.sql.connect.OpenSQLDataSourceImpl.setDataSourceName(OpenSQLDataSourceImpl.java:206)

This is strange considering I've never touched this automatically generated file. I belive it looks for this file in \usr\sap\<SID>\SYS\global\security\data. It's there. Is there something I am controlling on the java side that's causing it to look for it in the wrong place? Please advise.

JC

Former Member
0 Kudos

Hi Jason,

were you able to solve this?

I am facing the same issue.

thanks for your help

Former Member
0 Kudos

Hi Rakshit,

No I have not gotten past this issue yet.

Former Member
0 Kudos

I am getting this error

java.lang.NoClassDefFoundError: com/sap/sql/connect/OpenSQLDataSource

at com.sap.engine.services.dbpool.spi.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:102)

at com.sap.engine.services.dbpool.spi.DefaultConnectionManagerImpl.allocateConnection(DefaultConnectionManagerImpl.java:26)

at com.sap.engine.services.dbpool.cci.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:51)

But I found that opensqlsta.jar may solve this, but

Where to get opensqlsta.jar ?

Since my NWDS doesn't have this .jar in the plugins directory.

Thanks in Advance

Ananda

Former Member
0 Kudos

has anybody able to fix this problem?

Erin2
Advisor
Advisor
0 Kudos

try this

try{

Context ctx = new InitialContext();

DataSource ds = ctx.lookup("jdbc/SAPJ2EDB");

}

...

Cheers!

Erin

Former Member
0 Kudos

Hi Erin,

I was using the following environment to create the context before:

Hashtable env = new Hashtable();

env.put(

Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

env.put(Context.PROVIDER_URL, "localhost:50004");

and then I'd call

Context ctx = new InitialContext( env ); ....

When I tried what you suggested:

Context ctx = new InitialContext(); ....

I get a different exception on the constructor for the initial context.

Anyway, the current exception I am getting is when I call getConnection().

Let me know if you have another suggestion.

Thanks,

JC

Erin2
Advisor
Advisor
0 Kudos

Oh, sorry I mis-read the first post. Have you tried adding an alias to the SAPJ2EDB data source and connecting to that instead...maybe the j2ee would rather the connections come in via alias...

It's probably worth a quick test.

Thanks, Erin