Skip to Content
author's profile photo Former Member
Former Member

Swing Application connecting to datasource returning a NamingException

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 01:59 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 02:07 PM

    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");

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.