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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

im implementing connection pooling with tomcat, i configured web.xml file, context.xml. I configured my class file also, at the time of running im getting error like

"""""
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
org.apache.jsp.index_jsp._jspx_meth_sql_005fquery_005f0(index_jsp.java:102)
org.apache.jsp.index_jsp._jspService(index_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.29 logs.


My context file is...


<?xml version="1.0" encoding="UTF-8"?>
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="hbs" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:8080/mohi">
</Resource>

</Context>
===========================

My web.xml file is..

<resource-ref>
<description> DB Connection Pooling</description>
<res-ref-name> jdbc/conpooling</res-ref-name>
<res-type> javax.sql.DataSource</res-type>
<res-auth> Container</res-auth>
</resource-ref>

<servlet>
<servlet-name> DBBroker</servlet-name>
<servlet-class> com.DBBroker</servlet-class>
<load-on-startup> 1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name> DBBroker</servlet-name>
<url-pattern> /DBBroker</url-pattern>
</servlet-mapping>

================================

My class file is..

public class DBBroker extends HttpServlet
{
private static DataSource datasource = null;

/**
* Setup our connection pool when this servlet is started.
* Note that this servlet must be started before any other servlet that tries to
* use our database connections.
*/
public void init() throws ServletException
{
try
{
InitialContext initialContext = new InitialContext();
if ( initialContext == null )
{
String message = "There was no InitialContext in DBBroker. We're about to have some problems.";
System.err.println("*** " + message);
throw new Exception(message);
}

// actual jndi name is "jdbc/mysql"
datasource = (DataSource) initialContext.lookup( "java:/comp/env/jdbc/mysql" );

if ( datasource == null )
{
String message = "Could not find our DataSource in DBBroker. We're about to have problems.";
System.err.println("*** " + message);
throw new Exception(message);
}
}
catch (Exception e)
{
throw new ServletException(e.getMessage());
}
}

/**
* Dole out the connections here.
*/
public static synchronized Connection getConnection()
throws SQLException
{
return datasource.getConnection();
}

/**
* Must close the database connection to return it to the pool.
*/
public static synchronized void freeConnection(Connection connection)
{
try
{
connection.close();
}
catch (Exception e)
{
System.err.println("DBBroker: Threw an exception closing a database connection");
e.printStackTrace();
}
}


}


Please help me..
Regards,
MOHI
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic