on 04-15-2005 3:49 AM
Hi,
Is it possible to retrieve an Open SQL database connection from a console Java application? I have tried the code below with no luck. What JARs shold be added to the classpath? I've tried adding sapj2eeclient.jar, logging.jar, and exception.jar are there others? Any help is very much appreciated.
-Jason
Properties ctxProp = new Properties();
ctxProp.put(Context.INITIAL_CONTEXT_FACTORY, com.sap.engine.services.jndi.InitialContextFactoryImpl");
ctxProp.put(Context.PROVIDER_URL, "jclinexp:50004");
ctxProp.put(Context.SECURITY_PRINCIPAL, "j2ee_admin");
ctxProp.put(Context.SECURITY_CREDENTIALS, "A1234567");
ctxProp.put("force_remote", "true");
context = new InitialContext(ctxProp);
dataSource = (DataSource)context.lookup("jdbc/client/jdbc/SAPJ2EDB");
conn = dataSource.getConnection();
Roland,
I am having the same issue (of finding the paths and the jars) and the exact same exception you are getting.
Have you found a solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your response Vladimir. I actually had jdbc20.jar included in my classpath but just didn't include it in my first post. The error I'm receiving is:
java.lang.NoClassDefFoundError: javax/resource/ResourceException
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
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:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getObjectFactoryFromReference(NamingManager.java:129)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:299)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:497)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:614)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at com.testprojconsole.TestProjConsole.main(TestProjConsole.java:36)
Exception in thread "main"
So it's as if I'm missing a JAR but I'm not sure which one(s) I need.
Ok, thanks again. Making some progress now I have added connector.jar and then I received an error creating an OpenSQLConection so I added opensql.jar, opensqlapi.jar, opensqlcore.jar, and opensqlframe.jar but now I'm getting this exception trying to find SecStoreFSException. Here's the error stack:
java.lang.NoClassDefFoundError: com/sap/security/core/server/secstorefs/SecStoreFSException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1618)
at java.lang.Class.getConstructor0(Class.java:1930)
at java.lang.Class.newInstance0(Class.java:278)
at java.lang.Class.newInstance(Class.java:261)
at com.sap.sql.connect.OpenSQLDataSource.newInstance(OpenSQLDataSource.java:148)
at com.sap.sql.connect.OpenSQLDataSource.newInstance(OpenSQLDataSource.java:133)
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)
at com.testprojconsole.TestProjConsole.main(TestProjConsole.java:37)
Exception in thread "main"
Again, thanks in advance for your help!
Hi there,
I'm just trying to redo your post. Great until so far (btw. how do you find all those packages and paths?). Now I end up with another problem (see stackTrace below).
Thanks for your help in advanve.
Cheers,
Roland
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.sap.jdbc.JDBCTest.main(JDBCTest.java:73)
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)
... 1 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)
... 3 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)
... 5 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)
... 12 more
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.