Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

driver cannot be found error  RSS feed

rhett howard
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect my jsp app to the mysql database.I kept my app folder in webapps folder.Then i did all the necessary class path things for the driver and kept it in common/lib folder..
I am using tomcat 5 in windows vista which will be connected to a Mysql database in linux.
However, when i try to connect, I get this big scary error.
Could not find the database driver. Check the CLASSPATH SQLExceptionUnable to connect to any hosts due to exception: Connection timed out: connect ** BEGIN NESTED EXCEPTION ** MESSAGE: Connection timed out: connect STACKTRACE: Connection timed out: connect at com.mysql.jdbc.StandardSocketFactory.connect( at com.mysql.jdbc.MysqlIO.( at com.mysql.jdbc.Connection.createNewIO( at com.mysql.jdbc.Connection.( at com.mysql.jdbc.NonRegisteringDriver.connect( at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.jsp.sri.redirectuser22_jsp._jspService( at org.apache.jasper.runtime.HttpJspBase.service( at javax.servlet.http.HttpServlet.service( at org.apache.jasper.servlet.JspServletWrapper.service( at org.apache.jasper.servlet.JspServlet.serviceJspFile( at org.apache.jasper.servlet.JspServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.catalina.core.StandardWrapperValve.invoke( at org.apache.catalina.core.StandardContextValve.invoke( at org.apache.catalina.core.StandardHostValve.invoke( at org.apache.catalina.valves.ErrorReportValve.invoke( at org.apache.catalina.core.StandardEngineValve.invoke( at org.apache.catalina.connector.CoyoteAdapter.service( at org.apache.coyote.http11.Http11Processor.process( at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection( at at at org.apache.tomcat.util.threads.ThreadPool$ at Source) ** END NESTED EXCEPTION **

Please help me find a solution for this .The code goes like this.

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<p align="center">
String uid = request.getParameter("uid");
String pass = request.getParameter("pwd");

Connection connection;
Connection conn;
//Load the JDBC driver
String driverName = "com.mysql.jdbc.Driver";

//Define server environment
//String serverName = "";
//String portNumber = "1521";
//String sid = "CSORACLE";
//String url = "jdbc:mysql:" + serverName + ":" + portNumber + ":" + sid;
String url="jdbc:mysql://";
//Provide username and password
String username = "handyman";
String password = "tomnjerry";
//Create a connection to the database
connection = DriverManager.getConnection(url, username, password);
//Statement st=connection.createStatement();
PreparedStatement statement = connection.prepareStatement("select PASSWORD from LOGIN where USERID =? and PASSWORD=?");
ResultSet rset = statement.executeQuery();

//ResultSet rset= st.executeQuery("SELECT userid from LOGIN WHERE userid='uid' and password=?");
//return rset;
while( () )
//out.println("Login Successfull");

%> <jsp:forward page = "admin_menu.jsp" /> <%
<jsp:forward page="admin_login1.jsp">
<jsp:param name="bad" value="1"/>
<%//out.println(rset.getString("FNAME")+" "+rset.getString("LNAME"));

catch (SQLException e)
out.println("Could not find the database driver. Check the CLASSPATH");
out.println("\n SQLException" + e.getMessage()+"\n");



[ December 05, 2008: Message edited by: Bear Bibeault ]
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Verify that you can connect to mysql outside of Java. Not a good idea to have all that code in your JSP. You may want to refactor your database logic to the backend and call the backend via a servlet.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!