File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes driver cannot be found  error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "driver cannot be found  error" Watch "driver cannot be found  error" New topic

driver cannot be found error

rhett howard

Joined: Nov 24, 2008
Posts: 23
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

Joined: Nov 06, 2000
Posts: 1510
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.

So much trouble in the world -- Bob Marley
I agree. Here's the link:
subject: driver cannot be found error
It's not a secret anymore!