cancel
Showing results for 
Search instead for 
Did you mean: 

Error accessing JDBC alias name from Non J2EE application

Former Member
0 Kudos

Hi

I have got the error message while accessing alias name (FLIGHTDATA) from a non j2ee app eg. from main() method

com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception during lookup operation of object with name jdbc/FLIGHTDATA, cannot resolve object reference. [Root exception is com.sap.engine.services.connector.exceptions.BaseResourceException: Cannot lookup ManageConnectionFactory "SAPLKEDB". Cannot deserialize object: java.lang.NoClassDefFoundError: javax/resource/spi/ResourceAdapter

I have lookup as

DataSource dataSource =(DataSource) initCtx.lookup("jdbc/FLIGHTDATA");

PLEASE HELP

Thanks in advance

Ananda

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

hi anand,

I hope that ur problem is in adding external jars.

have u tried including the classes12.jar inside ur java build path appln.

Hope this might help u,

Regards,

Nagarajan.

Former Member
0 Kudos

hi

try as below,in the first lines give

Connection con=null;

...

....

....

con=ds.getConnection();

Former Member
0 Kudos

hi

i am having the following jar files.

opensql

opensqlapi

opensqlcore

opensqlframe

do u need it

regards,

purushothaman.

Former Member
0 Kudos

Hello

I have added the mentioned files along with opensqlsta.jar but it does not solve the problem .

Can anyone please help

Error is

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)

Thanks

Ananda

Former Member
0 Kudos

hi,

For external jars run on the server side place the particular jar under dist>PORTAL-INF>lib.

Reply if it works...

regards,

Ganesh.N

Former Member
0 Kudos

hi

Context ctx = new InitialContext();

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

con = ds.getConnection();

try using the above code...if its not working revert me back..

regards,

purushothaman.

Former Member
0 Kudos

I already used your code but from SDN I got the information that opensqlsta.jar might solve the problem.

Do you have that ?

Thanks

ANANDA

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Are you trying to connect the database directly?

If so, please start reading the manuals and learn how to access the DB over OpenSQL.

Otherwise please tell me how your connection is supposed to work.

Regards,

Benny

Former Member
0 Kudos

I have solved the above problem by including connection.jar from eclipse plugins.

I am accessing JDBC alias name from the main() menthod

Properties jndiCtxProp = new java.util.Properties();

jndiCtxProp.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );

jndiCtxProp.put(Context.PROVIDER_URL, "server:port");

jndiCtxProp.put(Context.SECURITY_PRINCIPAL, "yyy");

jndiCtxProp.put(Context.SECURITY_CREDENTIALS, "xxx");

Context initCtx = new InitialContext(jndiCtxProp);

DataSource dataSource =(DataSource) initCtx.lookup("jdbc/FLIGHTDATA");

conn = dataSource.getConnection(); //error

I am getting error in the last line

Error is

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)

at com.ibm.training.carrier.dbload.JDBCLoader.getConnect(JDBCLoader.java:63)

at com.ibm.training.carrier.dbload.JDBCLoader.doLoad(JDBCLoader.java:29)

PLEASE HELP

Thanks in advance

Ananda

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Ananda,

could you PLEASE read the

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/82/fdbf2085f65f43a71e755fc904478d/frameset.htm">Manuals</a>!!!

There you can find THE way how to do it!

We deliver also examples that make your live easier. Also, if you make up an appropriate project in NWDS, it delivery to you all the needed libs for FREE!

Regards,

Benny

Former Member
0 Kudos

Benny,

I am working with Ananda on this project (I do the cheerleading, he does the coding). We are quite familiar with the manuals you beg us to read. Those manuals explain how to get a resource connection <b>FROM A J2EE WEB OR EJB COMPONENT</b>. We have no problem doing that, we've done it a million times in non-SAP contexts and in our current SAP work. As the title of Ananda's posting explicitly says, however, our problem is in trying to get the db connection from a <b>STANDALONE JAVA PROGRAM</b>.

This is what we are trying to do: We have created some master data and transactional data tables in the Java Dictionary. (And again, we have accessed those tables from Web components using JDBC as well as from entity beans - Open SQL, standard stuff, no problem.) In our localhost WAS, we have used SQL Studio to insert some records into the master data tables for initial testing purposes. But for the server WAS, we are trying to write a standalone Java program to batch load records from a flat file into the tables. The outline of the standalone program is:

(1) Upon executing main(), the user gets a gui (Swing) with two buttons. First button is to select a flat file of data records (JFileChooser). Second button, "Load," initiates the data load.

(2) The data load action reads and validates the records from the flat file, puts them into some array structure, gets a connection to the database (this is where we are having the problem), uses JDBC to insert the records, and uses a JDBC query to read back the table and make sure the new data got there.

We are trying to get the db connection from code like the following (Ananda has tried many variations of this):

	
private void getConnection() {
		try {
			System.out.println("Getting database connection ...");
			InitialContext initCtx = new InitialContext();
			DataSource dataSource =
				(DataSource) initCtx.lookup("jdbc/FLIGHTDATA");
			conn = dataSource.getConnection();
		} catch (NamingException ex) {
			System.out.println("NamingException getting DataSource");
			System.exit(1);
		} catch (SQLException ex) {
			System.out.println("SQLException getting DataSource connection");
			System.exit(1);
		}
	}

We weren't surprised, intuitively, that from a standalone Java program this wasn't going to work quite this simply. And it didn't. As you can see from the thread, Ananda is hacking his way through adding any and all seemingly relevant libraries to the build path, but nothing has finally worked.

We've considered trying to make, or maybe having to make, this program a J2EE-compliant J2EE client application program. But in or outside of SAP, we have no experience with J2EE client app programs, and our reading of the SAP manuals suggests to us, perhaps incorrectly, that we would have to assemble a J2EE client app program from the SAP DeployTool - an undertaking the manuals touch on but fall short of the step-by-step instructions we would need.

Incidentally, we went through an analogous process trying to write a standalone Java program to test the call of a stateless session bean's business method. (The analogy being getting a connection to the bean.) In that case, with a little bit of luck, we hit upon the right combination of libraries to make it work.

Hopefully this provides a clearer idea for you of the context of our problem. Given that, any thoughts?<b></b><b></b><i></i><b></b>

Former Member
0 Kudos

P.S. I should have made it clear that we are developing the standalone Java program in NWDS.

Former Member
0 Kudos

Are you trying to access the servers context from a client java application. You do realize that "InitialContext" only gets you the context for the jvm that your code is running in. If that JVM is running on a client, then it can not get a handle to a datasource in the server JVM.

You can do one of two things.

1) Make URL connections to the server and get information that way.

2) Make a remote bean call.

Hope this helps. I really don't appreciate people just saying read the manuals either. We are all professionals here and I can't imagine people posting without doing there homework.

Former Member
0 Kudos

P.S. I should have also said that we solved the analogous challenge of connecting to an EJB from a standalone Java program not only with a little luck but also by reading the excellent SAP NW How-to Guide, <i>How to...EJB: Accessing EJB Applications Using JNDI</i>. That guide clearly distinguishes between accessing EJBs from J2EE components (including J2EE application clients, though unfortunately for us no example of this scenario is provided), J2EE components both local and remote to the EJB in question, and from non-J2EE components such as standalone Java applications (the example given being the pattern we successfully followed). We're asking for a similar guide or SDN help for non-J2EE-component access to the SAP db; to complete our education, a guide for access from a J2EE application client (how to assemble and deploy the app client as much as how to code it) would be gravy.

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Randy and Anand,

we're getting into sticky ground here for some reasons. First of all, the question is what kind of standalone programm you are using here. If it is a <b>standard remote programm</b> and intends to use the legal ways to access the server this way, then there should be a solution. It is also described in the manuals under "Connectivity and Interoperability" and may involve the genreation of some stubs and skeletons (I'm checking with a specialist on this at the moment).

Anyway, you have to use the sapj2eeclient.jar for this, which you can find at least on the server.

If you are trying to locally access the ressources of the server, this is highly forbidden. It is as forbidden as using direct connections to the SAP Tables in the DB via JDBC. I know this is done in real life under development conditions for special purposes - but it should not happen in a production system and therefore is not supported in any way from SAP. So, if this is your problem I'd wonder why you don't use direct JDBC.

Hope this helps further

Regards,

Benny

Message was edited by: Benny Schaich-Lebek

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Randy,

ok, that tells me more:

The difference for EJBs is that EJB delivers you the whole remote environment and generates stubs and skeletons for you (or even does this work dynamically, I don't know the latest and greatest).

However, exactly this is not done for a direct remote call on a standard class. If you are not familliar with stubs and skeletons (as the old DCE and Corba guys are), then I have to explain this further.

The solution should be that you have to generate those with the RMIC generator found in the deploying directory on the server. The documentation is around the chapters we already discussed. Your keyword is "RMI_P4", where P4 is the name of the servers internal protocol - but don't worry, you don't have to deal with it directly.

Let's see what this does.

Regards,

Benny

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Randy,

I asked development and they recommended not to do it this way as Datasource is not a remote object.

The only alternative doing it remote then is keeping with EJB (another possiblity would be servlets in a special way I don't like, but my colleague may describe).

Regards,

Benny

katarzyna_fecht
Explorer
0 Kudos

Hi Randy, Ananda,

Thank you very much for valuable contributions.

Last time we got many questions concerning accessing server side JDBC datasources from within remote Java programs. So let’s start with general and very short information:

As of SAP NetWeaver 04, accessing JDBC datasources from within remote client applications is a deprecated feature. Don’t adopt it in your system!

Follow the pattern: Remote clients don’t access server-side resources directly. Instead, they ask server-side components (servlet/JSP, EJB) to execute the intended work. Shift the operations from the remote client program onto the server side.

For example, accessing JDBC datasources from a standalone Java program is often done just to test the database connection and JDBC code quick. A recommended solution is: use a JSP page as your test client (a nice side effect: you get rid of finding out which server libraries must be in the remote client’s classspath … JSP pages live within the server and the server is providing them with necessary libs).

And now let’s take a look at your project. As you write, the task to solve is to insert data edited in the local file system into the application tables existing in the system database of the remote SAP Web AS Java. Check which of the following approaches could be a solution:

1.

Deploying table content as an sda of type DBSC.

(However, there is a general restriction for productive systems that there will not be any modification support for table entries delivered in this way.)

2.

If it is possible to deploy the source files along with your application, this is a sound alternative.

(EJB components are only allowed to read files deployed within an application. JSP/servlets can do this, too)

3.

Write a servlet, for example accepting the URI of the source file as a parameter.

(In general servlets are allowed to access external resources (files). Of course file access can be restricted if there is a security manager enabled on the server. Also you should take care that the server process has read/write permissions for the remote machine’s file system.)

4.

For test purposes, if you access the application database tables and nothing else from the server you could eventually access them directly via JDBC, without contacting the server at all. Use java.sql.DriverManager.getConnection(...) methods.

I hope this helps,

good luck, Katharina