• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

driver cannot be found error

rhett howard
Posts: 23
  • 0
  • 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: java.net.SocketException: java.net.ConnectException: Connection timed out: connect ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: java.net.ConnectException: Connection timed out: connect STACKTRACE: java.net.SocketException: java.net.ConnectException: Connection timed out: connect at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:225) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805) at com.mysql.jdbc.Connection.(Connection.java:452) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.jsp.sri.redirectuser22_jsp._jspService(redirectuser22_jsp.java:77) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown 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" "http://www.w3.org/TR/html4/loose.dtd">
<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 = "dione.cs.txstate.edu";
//String portNumber = "1521";
//String sid = "CSORACLE";
//String url = "jdbc:mysql:" + serverName + ":" + portNumber + ":" + sid;
String url="jdbc:mysql://sentry.cs.txstate.edu/sp1205";
//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( rset.next () )
//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: 1510
  • 0
  • 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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic