INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

MySQL Connection

MySQL Connection

(OP)
Hi all,

CODE

Connection conn = null;
    String url = "jdbc:mysql:///mysql12.000webhost.com\\";
    String dbName = "example";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root";
    String password = "root";

    try
    {
        Class.forName(driver).newInstance();
        out.println(url+dbName +userName +password);
        conn = DriverManager.getConnection(url+dbName, userName,password);
        
        try
        {
            Statement st = conn.createStatement();
            ResultSet res = st.executeQuery("SELECT * FROM  table1");
            out.println("Emp_code: " + "\t" + "Emp_name: ");
            while (res.next())
            {
                String s = res.getString("userid");
                String name = res.getString("Name");
                out.println(s + "\t\t" + name);
            }
        }
        catch (SQLException s)
        {
            out.println("SQL code does not execute.");
        }    
        
        conn.close();
        
    }
    catch (Exception e)
    {
    }

Class.forName(driver) errors with the following

CODE

org.apache.jasper.JasperException: An exception occurred processing JSP page /heading.jsp at line 19

19:         Class.forName(driver).newInstance();
20:         out.println(url+dbName +userName +password);
21:         conn = DriverManager.getConnection(url+dbName, userName,password);
22:         


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:551)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:440)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:915)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:844)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:173)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Unknown Source)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Is there anything i am missing here?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close