TarunAgarwal
Programmer
Hi,
I am trying to configure the server.xml file to create a connection pool (Oracle database) and access the same through my java code. I am not able to do so. Can I get a sample code from somewhere which actually works? I have tried using lots of code from internet, but they dont work. I am attaching a code snippet, which DOES NOT work.
"server.xml"
<Context path="" docBase="ROOT" debug="0">
<Resource name="jdbc/BPIDb" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/BPIDb">
<parameter>
<name>user</name>
<value>tiecom</value>
</parameter>
<parameter>
<name>password</name>
<value>tiecom</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbcracle:thin172.25.42.23:1526:yellow</value>
</parameter>
</ResourceParams>
"Java Code to access this"
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env"
DataSource ds = (DataSource) envCtx.lookup("jdbc/BPIDb"
Connection conn = ds.getConnection();
Here I get a null pointer for "ds".
Also, I would like to use the code for configuring SQL server. What all parameters do I need to change for that? A sample code would be of great help.
Regards,
Tarun.
I am trying to configure the server.xml file to create a connection pool (Oracle database) and access the same through my java code. I am not able to do so. Can I get a sample code from somewhere which actually works? I have tried using lots of code from internet, but they dont work. I am attaching a code snippet, which DOES NOT work.
"server.xml"
<Context path="" docBase="ROOT" debug="0">
<Resource name="jdbc/BPIDb" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/BPIDb">
<parameter>
<name>user</name>
<value>tiecom</value>
</parameter>
<parameter>
<name>password</name>
<value>tiecom</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbcracle:thin172.25.42.23:1526:yellow</value>
</parameter>
</ResourceParams>
"Java Code to access this"
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env"
DataSource ds = (DataSource) envCtx.lookup("jdbc/BPIDb"
Connection conn = ds.getConnection();
Here I get a null pointer for "ds".
Also, I would like to use the code for configuring SQL server. What all parameters do I need to change for that? A sample code would be of great help.
Regards,
Tarun.