File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Unable to get connection, DataSource invalid: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"" Watch "Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"" New topic
Author

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

Mohammed Mohideen
Greenhorn

Joined: Jun 24, 2010
Posts: 5
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
Shyam Kotnana
Greenhorn

Joined: Jul 15, 2010
Posts: 3
Hello Mohi,

Have you set your classpath with the required jar for the respective database dirver? if so, better have a look on to you java code build path. Check the confiruration perfectly once more.

Regards,
Shyam.
Mohammed Mohideen
Greenhorn

Joined: Jun 24, 2010
Posts: 5
Thank you Shyam.... I'll check it..

Thanks & Regards,
MOHI
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
 
Similar Threads
rg.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLExcepti
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
Problems Conectiong Database to a WebApplication - Unable to get connection, DataSource invalid
JDBC Exception: Cannot create PoolableConnectionFactory (validationQuery didn't return a row
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"