This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes datasource??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "datasource???" Watch "datasource???" New topic
Author

datasource???

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
Im testing datasource in tomcat using oracle(database).i configure the server.xml as well as the web.xml,but when i try to run my jsp page im getting an error message "the network adapter cannot make connection.....".But when i try to hard code it, the normal way of connecting to the database(Class.forname(),DriverManager.getConnection) it works fine.
here's my configuration of the server.xml and web.xml.
first, i added these code in the server.xml
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>bcms_owner</value>
</parameter>
<parameter>
<name>password</name>
<value>bcms_owner</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc racle:thin:@192.168.16.38:1521:BCMSDEV</value>
</parameter>
</ResourceParams>
</Context>
******************
then in the web.xml, i appended this
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
********************8

here's my jsp

<%@page import="javax.naming.*,javax.sql.*,java.sql.*"%>
<html>
<head><title>JSP Page</title></head>
<body>
<%
/* /****if i used this code it works fine***/
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc racle:thin:@192.168.16.38:1521:BCMSDEV","bcms_owner","bcms_owner");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from b_users");
if(rs.next()) {
System.out.println(rs.getString(1));
}
}
catch(Exception e)
{
e.printStackTrace();
}*/
/*** but with the datasource im getting an error ****.
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from b_users");
if(rs.next()) {
System.out.println(rs.getString(1));
}
}catch(Exception e) {
e.printStackTrace();
}
%>
</body>
</html>
thanks in advance

raymond
kavitha rama
Ranch Hand

Joined: Jun 18, 2003
Posts: 38
Hi,
Your web.xml is right but I am not sure of server.xml, we use Oracle 9iAS, so we configure in data-sources.xml
Anyway try following in your code
InitialContext ctx=new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mmrrcdb");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: datasource???
 
Similar Threads
Configuring DataSource on Tomcat5.0
javax.naming.NamingException- Cannot create resource instance
Is this true: JNDI equals Connection Pooling
JNDI in webapps
Pooling w/Tomcat 5 - Oracle