on 10-11-2005 2:33 PM
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
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");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem you are describing is Architectural not the idea behind DataSources and EJBs. EJBs 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 EJBs are the application layer for your swing gui.
I know this is not a solution for your problem. But I hope this will help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.