You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ox...@comcast.net on 2004/09/23 21:17:23 UTC
Thanks very much all -- Oracle driver now loading :)
What I changed:
Tomcat 5.0.19 which was installed when I installed NetBeans 3.6
To
Tomcat 5.0.28
I am unsure if the NetBeans 3.6 caused the issue or something else was. Maybe, the install just went a bit weird on my XP box. What finally made me try a stand alone Tomcat install was the Management tool did not function correctly. The logging was not working as well. Therefore I said why not, nothing else has worked.
I did not use a default context or a context in the server.xml instead I used
C:\Tomcat5.0.28\conf\Catalina\localhost\dbtest1.xml
Here's that file:
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:\Tomcat5.0.28\webapps\dbtest1" path="/dbtest1">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="DBTest" suffix=".log" timestamp="true"/>
<Resource name="jdbc/OracleDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/OracleDB">
<parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@192.168.1.10:1521:to1</value>
</parameter>
<parameter>
<name>username</name>
<value>myuser</value>
</parameter>
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
My server.xml is still at the default. I did not change a thing. Therefore I will not include it.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
<welcome-file>
index.html
</welcome-file>
<welcome-file>
index.htm
</welcome-file>
</welcome-file-list>
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/OracleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Here is my app code:
/*
* testDBConnBean.java
*
* Created on September 23, 2004, 11:14 AM
*/
package mybean;
import java.beans.*;
import java.io.Serializable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
public class testDBConnBean extends Object implements Serializable {
private String message1 = "error";
public String testJDBCDBConn() throws Exception {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/OracleDB");
Connection conn = ds.getConnection();
message1="no error";
return message1;
}
public String testODBCJDBCDBConn() throws Exception{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbcodbc/OracleDB");
Connection conn = ds.getConnection();
return "no error";
}
public String getMessage1(){
return message1;
}
}
I do have one question: How the the "java:/comp/env" work in the line:
Context envContext = (Context)initContext.lookup("java:/comp/env");
do?
Thanks
Pete