Hi,

I am having difficulty in connecting jsp and mysql using Tomcat 7.0 .
I downloaded jdbc driver "mysql-connector-java-5.1.15-bin.jar" and placed it
in two locations:

   - CATALINE_HOME\lib
   - C:\Program Files\Apache Software Foundation\Tomcat
   7.0\webapps\lsc\WEB-INF\lib

I tried to connect using the following code but it always says:"Cannot
connect to database server".
 Do i need to make any configurations apart from this ?
I tried to connect with the following code:
  <%@page language="java" import="java.sql.*"%>
        <%
  Connection conn = null;

          try
           {
               String userName = "root";
               String password = "nbuser";
               String url = "jdbc:mysql://localhost:3306/test";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, password);
               out.println ("Database connection established");
           }
           catch (Exception e)
           {
               out.println ("Cannot connect to database server");
           }
           finally
           {
               if (conn != null)
               {
                   try
                   {
                       conn.close ();
                       out.println ("Database connection terminated");
                   }
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
%>

Reply via email to