I have been trying to use DataSource in Websphere App Server 3.5..
I have coded as below..
InitialContext ctx = null;
javax.sql.DataSource ds = null;
try {
java.util.Hashtable env= new java.util.Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
env.put("javax.naming.Context.PROVIDER_URL","IIOP://localhost:900/");
// Create the Initial Naming Context.
ctx = new InitialContext(env);
ds = (javax.sql.DataSource) ctx.lookup ("TestDataSource");
ds.getConnection(); }
catch (Throwable theException) {
// Handle Exception
theException.printStackTrace();
}
The problem is it is giving a compilation error saying that 'ds'(DataSource) doesnot contain the method getConnection()..I am not able to access any methods in the DataSource..Pls respond...
Thanks in Advance
--Raj
-
Problem using 'DataSource' in Websphere (5 messages)
- Posted by: Raj Shekar
- Posted on: March 06 2001 14:01 EST
Threaded Messages (5)
- Problem using 'DataSource' in Websphere by Evan Schnell on March 06 2001 17:23 EST
- Problem using 'DataSource' in Websphere by Raj Shekar on March 07 2001 09:36 EST
- Problem using 'DataSource' in Websphere by Dan Josephs on March 07 2001 10:08 EST
- Problem using 'DataSource' in Websphere by Raj Shekar on March 07 2001 13:23 EST
- Problem using 'DataSource' in Websphere by Dan Josephs on March 07 2001 01:31 EST
- Problem using 'DataSource' in Websphere by Raj Shekar on March 07 2001 13:23 EST
-
Problem using 'DataSource' in Websphere[ Go to top ]
- Posted by: Evan Schnell
- Posted on: March 06 2001 17:23 EST
- in response to Raj Shekar
I have never seen this problem.
Perhaps there is a a problem with the cast. When you are using IIOP you usually should not blindly cast the result of a lookup. Instead cast the result of javax.rmi.PortableRemoteObject.narrow(ctx.lookup("name"), Datasource.class) to DataSource.
Evan. -
Problem using 'DataSource' in Websphere[ Go to top ]
- Posted by: Raj Shekar
- Posted on: March 07 2001 09:36 EST
- in response to Evan Schnell
Hi
I tried that way...but still the problem persists -
Problem using 'DataSource' in Websphere[ Go to top ]
- Posted by: Dan Josephs
- Posted on: March 07 2001 10:08 EST
- in response to Raj Shekar
Try calling ds.getConnection() with two parameters... user name and password...
ex.
Connection conn = ds.getConnection(user, password); -
Problem using 'DataSource' in Websphere[ Go to top ]
- Posted by: Raj Shekar
- Posted on: March 07 2001 13:23 EST
- in response to Dan Josephs
The problem is the DataSource object 'ds' is not showing up any methods..There seems to be some casting problem with this DataSource object(It is an interface..)..I am using Visual Age for Java as my development tool..
Regards - Raj -
Problem using 'DataSource' in Websphere[ Go to top ]
- Posted by: Dan Josephs
- Posted on: March 07 2001 13:31 EST
- in response to Raj Shekar
Try this code it works for me... also make sure you import javax.sql.*
try{
Hashtable parms = new Hashtable();
parms.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
parms.put(
Context.PROVIDER_URL,
"iiop://sun522concept-dev/");
Context ctx = new InitialContext(parms);
DataSource ds = (DataSource) ctx.lookup
("jdbc/WecsDB");
Connection conn =
ds.getConnection"tptux", "tptux1");
conn.close();
}
catch(Exception e){
e.printStackTrace();
}