I have the following error connecting to database using java:
type Exception report
message java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
com.skf.support.setup.data.database.DBConnectionFactory.getConnection(DBConnectionFactory.java:32)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:25)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:54)
com.skf.support.setup.data.login.LoginFormValidator.validate(LoginFormValidator.java:28)
org.apache.jsp.modules.login.doLogin_jsp._jspService(doLogin_jsp.java:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
com.skf.support.setup.data.database.DBConnectionFactory.getConnection(DBConnectionFactory.java:23)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:25)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:54)
com.skf.support.setup.data.login.LoginFormValidator.validate(LoginFormValidator.java:28)
org.apache.jsp.modules.login.doLogin_jsp._jspService(doLogin_jsp.java:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getDriver(DriverManager.java:315)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
com.skf.support.setup.data.database.DBConnectionFactory.getConnection(DBConnectionFactory.java:23)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:25)
com.skf.support.setup.data.user.UserDao.checkUser(UserDao.java:54)
com.skf.support.setup.data.login.LoginFormValidator.validate(LoginFormValidator.java:28)
org.apache.jsp.modules.login.doLogin_jsp._jspService(doLogin_jsp.java:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.
I am using phpmyadmin and my database name is: sfsupportconnectionpool
Here is my web.xml
<resource-ref>
<description>Resource reference to a factory for java.sql.Connection instances
that may be used for talking to a particular database
that is configured in the Context
configuration for the web application.</description>
<res-ref-name>jdbc/SFSupportConnectionPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/SFSupportConnectionPool">
<Resource
name="jdbc/SFSupportConnectionPool"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="dbadmin" password="12345"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sf_support?autoReconnect=true"
connectionProperties="removeAbandoned=true; removeAbandonedTimeout=60;"/>
</Context>
class for connecting to db: DBConnection.java
package com.skf.support.setup.data.database;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class DBConnectionFactory{
private static String dbName = "SFSupportConnectionPool";
public static Connection getConnection(){
Context initContext;
try{
initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/" + DBConnectionFactory.dbName);
Connection conn = ds.getConnection();
return conn;
}
catch (NamingException e){
e.printStackTrace();
throw new RuntimeException(e);
}
catch (SQLException e){
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
I tried a number of things but its not working out for me. Could anyone suggest me what could be going wrong here? I didn't create the project myself i am just trying to connect the database to the jsp application. Any help would be appreciated.! Thanks
I tested this tutorial and it works perfectly http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html;
U have to read and understand it ,don't worry it's easy and it took me only 10 minutes to do it.
This is my test project,i am pretty sure that it will work.
https://www.dropbox.com/s/xx5i3zip5ohmls9/testt.zip
You have to put the mysql jar file inside lib directory of the tomcat server.
(eg: C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\lib)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With