Bookmark Topic Watch Topic
  • New Topic

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

 
Mohammed Mohideen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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




 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please use our Tomcat sub-forum for Tomcat related questions. This forum is for JBoss specific questions. I'll move this thread there.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
This thread appears 3 times. I've locked all but one of them, to avoid the perils of parallel conversations.
 
    Bookmark Topic Watch Topic
  • New Topic