Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

DataSource Pooling  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a problem in the following servlet program.

I added the resource tag to "server.xml",which contains all the details about database connection and about the number of connections it has to open.

<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/myoracle">
<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 racle:thin:@ORASRV:1521:MIRACLE</value>
</parameter>
<parameter>
<name>username</name>
<value>itg10</value>
</parameter>
<parameter>
<name>password</name>
<value>itg10</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>


And my "web.xml" file contains


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

<resource-ref>
<description>Oracle DataSource Example </description>
<res-ref-name>jdbc/myoracle </res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<servlet>
<servlet-name>employee</servlet-name>
<servlet-class>EmployeeDetails</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>employee</servlet-name>
<url-pattern>/remployee</url-pattern>
</servlet-mapping>

</web-app>

And my servlet class contains

import javax.servlet.*;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.naming.InitialContext.*;

public class EmployeeDetails extends GenericServlet
{
public void init()
{
System.out.println("Servlet Intialised");
}
public void service(ServletRequest request,ServletResponse response) throws ServletException,IOException
{
PrintWriter out=null;
try
{
response.setContentType("text/html");
out=response.getWriter();

Context initContext=new InitialContext();
Context encContext=(Context)initContext.lookup("java:/comp/env");
DataSource ds=(DataSource)encContext.lookup("jdbc/myoracle");
//DataSource ds=(DataSource)initContext.lookup("java:/comp/env/jdbc/myoracle");
Connection con=ds.getConnection();
System.out.println("Connection Created");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from emp1");
//Statement st1=con.createStatement();
//ResultSet rs1=st1.executeQuery("Select * from r_employee");
out.println("<html><body><br>");
while(rs.next())
{
out.println(rs.getInt(1)+"<br>");
}
//out.println("<br><br>R_Employee");
//while(rs1.next())
//{
//out.println(rs1.getInt(1)+"<br>");
// }

out.println("Resultset Processed </body></html>");
out.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
out.println(e);
}
}
public void destroy()
{
System.out.println("Servlet Destroyed");
}
}

and i wrote the html file also

iam getting an error as

java.sql.SQLException: Cannot load JDBC driver class 'null'

Is there is any problem with in server.xml or in the servlet class file

Please tell me where is the problem and how to solve it.
 
Marshal
Posts: 67239
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post the same question more than once.
 
They weren't very bright, but they were very, very big. Ad contrast:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!