hai,
This is the sample code :
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("dbJNDIRef");
Connection connection = ds.getConnection();
Statement statement=connection.createStatement();
ResultSet result=statement.executeQuery(Sql);
boolean exist=result.next();
result.close();
statement.close();
connection.close();
I have added dbJNDI as JNDI name for a datasource thru the Datasource link of admin area of Tomcat. The property Data Source URL has been set to jdbc:odbc:test( here, test refers to the dsn for a SQLServer database).
Next , I created a resource link with the properties set as name:dbJNDIRef, global :dbJNDI , type :javax.sql.DataSource in the admin area .
After deployment, this is the error shown in the stdout.log file:
javax.naming.NameNotFoundException.
Plz help meeee.
SK
-
Tomcat database configuration (2 messages)
- Posted by: s k
- Posted on: March 21 2005 04:15 EST
Threaded Messages (2)
- Tomcat database configuration by Paul Morie on March 21 2005 18:23 EST
- Tomcat database configuration by nisha kumar on March 23 2005 07:16 EST
-
Tomcat database configuration[ Go to top ]
- Posted by: Paul Morie
- Posted on: March 21 2005 18:23 EST
- in response to s k
Hi SK-
You don't need to add a resource reference. Just add a JNDI name for the data source and you can look it up via:
String TOMCAT_JNDI_CONTEXT = "java:comp/env/"
String myDataSourceJNDIName = "dbJNDI";
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(TOMCAT_JNDI_CONTEXT + myDataSourceJNDIName);
Hope that makes sense. You should also check out the Service Locator pattern to save yourself some tedious lookup operations.
HTH,
P -
Tomcat database configuration[ Go to top ]
- Posted by: nisha kumar
- Posted on: March 23 2005 07:16 EST
- in response to Paul Morie
hai Paul ,
Thank u for the help. It worked.
sk