| Author |
driver cannot be found error
|
rhett howard
Greenhorn
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. [code] 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 ** [code] Please help me find a solution for this .The code goes like this. [code] <%@ 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"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <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"; Class.forName(driverName); //Create a connection to the database try{ connection = DriverManager.getConnection(url, username, password); //if(!connection.isClosed()){ //Statement st=connection.createStatement(); PreparedStatement statement = connection.prepareStatement("select PASSWORD from LOGIN where USERID =? and PASSWORD=?"); statement.setString(1,uid); statement.setString(2,pass); 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"/> </jsp:forward> <%//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"); } %> </body> </html> [code] [ December 05, 2008: Message edited by: Bear Bibeault ]
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
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.
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
 |
|
|
subject: driver cannot be found error
|
|
|