richardsimnett
asked on
Tomcat 6: Datasource Problems
Hello,
I recently converted a glassfish application over to Tomcat 6. The application functions about 95% but 5 servlets are failing with the following exception:
Cannot create JDBC driver of class '' for connect URL 'null'
The odd thing is the same exact code to interact with the databases are used in the other 95 or so servlets without any issue at all, so it is really beyond me as to why these dont work. I have been over google and the issue seems common but caused for MANY MANY MANY different reasons. I was hoping maybe someone more experienced with Tomcat than me (Im brand new to it), could have a look and tell me what Im missing or doing wrong.
I have attached a copy of the "copy" servlet to review. Here is the output generated by the servlet. It indicates that the exception is being thrown during the initialization of the datasource.
call copyList('6721','a','cl051 1201110435 7308',61,2 56); SQL: During Copy - Cannot create JDBC driver of class '' for connect URL 'null'
A working fix is worth 500 points.
Thanks,
Rick
I recently converted a glassfish application over to Tomcat 6. The application functions about 95% but 5 servlets are failing with the following exception:
Cannot create JDBC driver of class '' for connect URL 'null'
The odd thing is the same exact code to interact with the databases are used in the other 95 or so servlets without any issue at all, so it is really beyond me as to why these dont work. I have been over google and the issue seems common but caused for MANY MANY MANY different reasons. I was hoping maybe someone more experienced with Tomcat than me (Im brand new to it), could have a look and tell me what Im missing or doing wrong.
I have attached a copy of the "copy" servlet to review. Here is the output generated by the servlet. It indicates that the exception is being thrown during the initialization of the datasource.
call copyList('6721','a','cl051
A working fix is worth 500 points.
Thanks,
Rick
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package servlets.administrator.lists.controls;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.*;
import java.util.*;
import java.io.*;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
/**
*
* @author rick
*/
public class copy extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
if (request.isRequestedSessionIdValid())
{
//first generate a unique tablename
java.util.Date d = new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyyhhmmssSSS");
//collect the required data (list to copy, and listname)
String list = request.getParameter("id").toString();
String listname = request.getParameter("listname").toString();
String userid = request.getSession().getAttribute("userid").toString();
String parent = request.getSession().getAttribute("parent").toString();
String newtablename = "cl" + sdf.format(d);
//now setup a database connection
StringBuilder query = new StringBuilder();
query.append("call copyList('");
query.append(list);
query.append("','");
query.append(listname);
query.append("','");
query.append(newtablename);
query.append("',");
query.append(userid);
query.append(",");
query.append(parent);
query.append(");");
out.println(query);
InitialContext context = null;
DataSource ds = null;
Connection con = null;
Statement stmt = null;
ResultSet tmp = null;
try
{
/* Get the connection */
Context envContext = (Context) new InitialContext().lookup("java:/comp/env");
ds = (DataSource) envContext.lookup("jdbc/data_pool");
con = ds.getConnection();
stmt = con.createStatement();
out.println("Execute Query");
/* Query and Get Result */
tmp = stmt.executeQuery(query.toString());
out.println("Done.");
if (tmp.next())
{
query = new StringBuilder();
query.append("insert into lists (listname,tablename,originalsize,currentsize,status,parent,client_id,filename) values('");
query.append(listname);
query.append("','");
query.append(newtablename);
query.append("',0,0,3,");
query.append(parent);
query.append(",");
query.append(userid);
query.append(",'')");
out.println(query.toString());
stmt.close();
ds = (DataSource) envContext.lookup("jdbc/tracking_pool");
con = ds.getConnection();
stmt = con.createStatement();
stmt.executeUpdate(query.toString());
out.println("List Copy Successful.");
}
else
out.println("Copy failed at insert list data.");
}
catch(SQLException sq)
{
out.println("SQL: During Copy - " + sq.getMessage());
}
catch(Exception e)
{
out.println("Exception: During Copy - " + e.getMessage());
}
finally
{
try
{
if (con != null)
con.close();
}
catch(Exception e)
{
}
}
con = null;
stmt = null;
ds = null;
context = null;
tmp = null;
query = null;
}
else
{
out.println("logout");
}
} catch (Exception e) {
out.println(e.getMessage());
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
They are saying in similar situation it shoule be in CATALINA_HOME/lib.
Where do you have your database driver jar file located?
If you use JNDI it must be located in the container specific library directory not in your application library directory.
E.g. for Tomcat 6.0.14 it must be CATALINA_HOME/lib.
Hope that helps.
memento
Where do you have your database driver jar file located?
If you use JNDI it must be located in the container specific library directory not in your application library directory.
E.g. for Tomcat 6.0.14 it must be CATALINA_HOME/lib.
Hope that helps.
memento
ASKER
for_yan,
No Dice. I removed the driver from jre/lib/ext and moved it directly to the tomcat/lib directory. It is not packaged with the application (and never was).
No Dice. I removed the driver from jre/lib/ext and moved it directly to the tomcat/lib directory. It is not packaged with the application (and never was).
And these other servlets with the same code connect to the same instance of the database without any problem?
An now you moved driver - they all contniue to work and these few servlets didn't work before and don't work now?
If so, it is difficult to understand, probably some combination of problems.
An now you moved driver - they all contniue to work and these few servlets didn't work before and don't work now?
If so, it is difficult to understand, probably some combination of problems.
ASKER
for_yan,
Yep. No problem at all. I have attached a copy of a working servlet (from the same group of "lists" servlets) that uses the same datasource.
With the moved driver all the ones that worked previously still work, the ones that were broken are still broken.
Yep. No problem at all. I have attached a copy of a working servlet (from the same group of "lists" servlets) that uses the same datasource.
With the moved driver all the ones that worked previously still work, the ones that were broken are still broken.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package servlets.administrator.lists;
import java.io.*;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author rick
*/
public class viewlists extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {//first we check to make sure we are logged in
if (request.isRequestedSessionIdValid())
{
String userid = request.getSession().getAttribute("userid").toString();
String sort = request.getParameter("sort").toString().replaceAll(":", " ");
StringBuilder query = new StringBuilder();
query.append("select * from lists where (client_id = ");
query.append(userid);
query.append(" or client_id = 0) and active = 1");
query.append(" order by ");
query.append(sort);
//out.println(query);
InitialContext context = null;
DataSource ds = null;
Connection con = null;
Statement stmt = null;
ResultSet tmp = null;
try
{
/* Get the connection */
Context envContext = (Context) new InitialContext().lookup("java:/comp/env");
ds = (DataSource) envContext.lookup("jdbc/tracking_pool");
con = ds.getConnection();
stmt = con.createStatement();
/* Query and Get Result */
tmp = stmt.executeQuery(query.toString());
tmp.last();
int rows = tmp.getRow();
tmp.beforeFirst();
if (rows > 0)
{
while (tmp.next())
{
String lib = "";
int id = new Integer(tmp.getString("id")).intValue();
if ((id == 2987) || (id == 4869) || (id == 2985) || (id == 2986) || (id == 4870) || (id == 4871))
{
out.print("<tr class=\"listlib\">");
lib = "MP Library";
}
else if (tmp.getString("tablename").compareToIgnoreCase("delivered" + userid) == 0)
{
out.print("<tr class=\"autolib\">");
lib = "Deliverables";
}
else if (tmp.getString("tablename").compareToIgnoreCase("openers" + userid) == 0)
{
out.print("<tr class=\"autolib\">");
lib = "Openers";
}
else if (tmp.getString("tablename").compareToIgnoreCase("clickers" + userid) == 0)
{
out.print("<tr class=\"autolib\">");
lib = "Clickers";
}
else
out.print("<tr class=\"stat\">");
out.print("<td class=\"ac narrow\"><input type=checkbox value=\"");
out.print(tmp.getString("id"));
out.print("\" name=\"check\"></td>");
out.print("<td class=\"ac cellNumber\">");
int status = new Integer(tmp.getString("status")).intValue();
int datafeed = new Integer(tmp.getString("datafeed")).intValue();
if (status == 3)
{
out.print("<div style=\"float: left\"><small>" + lib + "</small></div>");
out.print("<a href=\"manager.jsp?where=lists&where2=liststats&id=");
out.print(tmp.getString("id"));
out.print("\">");
out.print(tmp.getString("listname"));
out.print("</a>");
if (datafeed == 1)
{
out.print("<small>(Feed_ID: ");
out.print(tmp.getString("id"));
out.print("</small>");
}
}
else
out.print(tmp.getString("listname"));
out.print("</td>");
out.print("<td class=\"ac cellNumber\">");
if (status == 0)
out.print("Import Queue.");
else if (status == 1)
out.print("Scrub in Progress.");
else if (status == 2)
out.print("Import in Progress.");
else if (status == 3)
out.print("Ready For Use.");
else
{
out.print("<font color=red>");
out.print(status);
out.print(" - ");
out.print(tmp.getString("errorMsg"));
out.print("</font>");
}
out.println("</td></tr>");
}
}
else
out.println("<td class=\"ac cellNumber\" colspan=\"4\">Sorry, You dont have any lists.</td>");
}
catch(SQLException sq)
{
out.println("SQL Exception During View Offers<br><br>" + sq.getMessage());
}
catch(Exception e)
{
out.println("Exception During View Offers<br><br>" + e.getMessage());
}
finally
{
try
{
if (con != null)
con.close();
}
catch(Exception e)
{
}
}
con = null;
stmt = null;
ds = null;
context = null;
tmp = null;
query = null;
}
else
{
out.println("logout");
}
} catch (Exception e) {out.println(e.getMessage());
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
I would be tempted to remove the jar from $CATALINA_HOME/lib *as well as* the ext directory. I wouldn't be surprised if some stuff still worked
ASKER
I have narrowed it down to this line that is throwing the exception:
con = ds.getConnection();
Thanks,
Rick
con = ds.getConnection();
Thanks,
Rick
Can you post the full stack trace from the log?
ASKER
cehj,
You're right about it still working after the removal from both places. However, the servlets are still broken. :(
You're right about it still working after the removal from both places. However, the servlets are still broken. :(
>>You're right about it still working after the removal from both places.
Thought so. You need to discover which driver IS being used and where it's being loaded from. If all else fails, start the vm with verbose classloading
Thought so. You need to discover which driver IS being used and where it's being loaded from. If all else fails, start the vm with verbose classloading
ASKER
call copyList('6721','test','cl 0511201103 0115511',6 1,256); SQL: During Copy - Cannot create JDBC driver of class '' for connect URL 'null' org.apache.tomcat.dbcp.dbc p.SQLNeste dException : Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.cr eateDataSo urce(Basic DataSource .java:1150 ) at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.ge tConnectio n(BasicDat aSource.ja va:880) at servlets.administrator.lis ts.control s.copy.pro cessReques t(copy.jav a:82) at servlets.administrator.lis ts.control s.copy.doG et(copy.ja va:171) at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 617) at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717) at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:290 ) at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06) at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:233) at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:191) at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:128 ) at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:102 ) at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :109) at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:293) at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:849) at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocess(Http 11Protocol .java:583) at org.apache.tomcat.util.net .JIoEndpoi nt$Worker. run(JIoEnd point.java :454) at java.lang.Thread.run(Threa d.java:636 ) Caused by: java.sql.SQLException: No suitable driver at java.sql.DriverManager.get Driver(Dri verManager .java:279) at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.cr eateDataSo urce(Basic DataSource .java:1143 ) ... 17 more
The ones that ARE working might not be using that datasource at all ...
ASKER
cehj,
I just checked the enter machine for *mysql*.jar, and came up with two drivers. 5.1.6 in my netbeans/ide52/lib directory and another in netbeans under ruby (5.0.4). I deleted the ruby one leaving only one on the machine.
For the record, this is being run from netbeans on the local install of tomcat while I am working the kinks out of it.
Thanks,
rick
I just checked the enter machine for *mysql*.jar, and came up with two drivers. 5.1.6 in my netbeans/ide52/lib directory and another in netbeans under ruby (5.0.4). I deleted the ruby one leaving only one on the machine.
For the record, this is being run from netbeans on the local install of tomcat while I am working the kinks out of it.
Thanks,
rick
Please post server.xml
ASKER
cehj,
Actually things just started working. After removing those drivers, I shutdown tomcat and netbeans. Then restarted them and redeployed and boom, servlets work!
Thanks!
Actually things just started working. After removing those drivers, I shutdown tomcat and netbeans. Then restarted them and redeployed and boom, servlets work!
Thanks!
:)
ASKER