0
votes

I am using MySQL Workbench (5.6.19). It has several connections among which the table that i want to access is in "Connection1"(name of connection). Connection Host: 122.0.0.0 . My database name is "sorder". user = "root", password = "password",port = 3306.

Here's my piece of code:

try 
    {
        Class.forName("com.mysql.jdbc.Driver");
    } 
        catch (ClassNotFoundException e) 
            {

                PrintWriter pw = new PrintWriter(System.out, true); 
                pw.println("Driver Connection Failed."); 
                e.printStackTrace();

            }
    System.out.println("MySQL JDBC Driver Registered!");  
    Connection connection = null;

    try 
    {
    connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sorder","root", "password");

    } catch (SQLException e) 
    {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return;
    }

My driver connection failed. Plus i am not sure what my path Strin url should be since there are more than 1 connections in mySQL workbench.

error :

-------- MySQL JDBC Connection Testing ------------
Driver Connection Failed.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.apache.jsp.NewFile_jsp._jspService(NewFile_jsp.java:65)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

I followed whatever suggestions i got in different forums, like:

  • reassured that JAR file is there in build path.
  • reassured that JAR file is there in Window>Prefernces>Java>Build Path>Classpath variable
  • JAR file explicitily in WEB-INF/lib buildpath.

Thankful for any suggestions.

Regards.

1
thankyou @a_horse_with_no_name - user3595802
How are you running this piece of code? The mysql connector jar should be available in runtime. Therefore it doesn't matter that it's in your build path. - Eran
@Eran yes, JAR file is there in specified path during run time. - user3595802
i tried "telnet mydomainname.com 3306" in cmd, where mydomainanme is replaced with my actual domain name. Connection fails. I am writing connection code from within javabeans in a JSP page for a drop down. mySQL server and workbench is also in local pc. - user3595802
and i have checked in firewallsettings, port 3306 is not blocked. - user3595802

1 Answers

0
votes

when we manually created a xml file and added welcome-file-list, it worked. Default xml file was missing.