cancel
Showing results for 
Search instead for 
Did you mean: 

Swing Application connecting to datasource returning a NamingException

Former Member
0 Kudos

hello i created a swing that calls a data source of a webas 6.40 sp14

the lookup :

public static Context lookup()

{

if (ctx != null )return ctx;

else

try {

Properties props = new Properties();

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

props.put(Context.PROVIDER_URL, "10.2.82.78:50004");

props.put(Context.SECURITY_PRINCIPAL, "admin");

props.put(Context.SECURITY_CREDENTIALS, "password");

tx = new InitialContext(props);

return ctx;

}catch(Exception e){

e.printStackTrace();

return null;

}

}

the connection to the datasource :

public static Connection ConnectToDB(){

try {

if(ctx == null ){ Context ctx = SwingPanel.lookup(); }

Object o = ctx.lookup("jdbc/oracle");

javax.sql.DataSource ds = (javax.sql.DataSource) o ;

java.sql.Connection con = ds.getConnection();

return con;

}catch(Exception e){

e.printStackTrace();

return null;

the error :

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

at com.sap.engine.services.dbpool.spi.CPManagedConnectionFactoryImpl.readObject(CPManagedConnectionFactoryImpl.java:307)

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)

the following jars are in order :

connector , jdbc , jdbc20, logging , ojdbc14 (oracle ) ,sapj2eeclient ,exception , tools

the datasource is working , because in another part of the code i call a CMP EJB that uses this datasource . but on this part i have to use a direct connection to the datasource , any ideas

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

It is also possible to make a direct connection to the database like below. This is the why to do it outside a Java application server.

Summery

In this solution there is no shared database resource but an application specific.

try {

Class.forName ("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

Connection conn = DriverManager.getConnection

("jdbc:oracle:oci8:@hostname_orcl", "scott", "tiger");

Former Member
0 Kudos

The problem you are describing is Architectural not the idea behind DataSources and EJB’s. EJB’s are there for receiving and processing the data. So in your Java Swing client you should call the EJB en let the ejb get te right information that is needed in your swing application.

So your EJB’s are the application layer for your swing gui.

I know this is not a solution for your problem. But I hope this will help.

Former Member
0 Kudos

i agree with you and i would do it with swing - EJB , but i am in sales cycle and the customer wants to see this code working =[