• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

datasource???  RSS feed

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 love a good mentalist. And so does this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!