Results 1 to 12 of 12
  1. #1
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default MySql not connecting to Eclipse even after manually including

    Hey. I had started doing a project where i have to authenticate. I'm using a mysql database and was making a JSP. Now the issue is that its not connecting to the mysql driver even when i manually added it in the lib folder(yes, imported the j connector jar file in the lib). Need ur assistance and ideas


    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    String userName = request.getParameter("userName");
    String passWord = request.getParameter("password");

    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/userdb";
    String dbName = "userdb";
    String user = "root";
    String password = "magic";
    String sql = "SELECT * FROM userinfo WHERE USR_NAME = ? AND USR_PASS = ?";

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    boolean login = false;
    Class.forName("WEB-INF/lib/org/gjt/mm/mysql/Driver").newInstance();
    try {

    connection = DriverManager.getConnection(url, "root", "magic");
    statement = connection.prepareStatement(sql);
    statement.setString(1, userName);
    statement.setString(2, password);
    resultSet = statement.executeQuery();
    login = resultSet.next();
    } catch (Exception e) {
    throw new ServletException("Login failed", e);
    }
    finally {
    }

    if (login) {
    request.getSession().setAttribute("username", userName);
    response.sendRedirect("logged.jsp");
    } else {
    out.println("Unknown username/password, try again");
    request.getRequestDispatcher("home.jsp").forward(r equest, response);
    }

    %>
    </body>
    </html>



    Here's the damned error

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)


    root cause

    javax.servlet.ServletException: java.lang.ClassNotFoundException: WEB-INF/lib/org/gjt/mm/mysql/Driver
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:911)
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:840)
    org.apache.jsp.login_jsp._jspService(login_jsp.jav a:120)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)


    root cause

    java.lang.ClassNotFoundException: WEB-INF/lib/org/gjt/mm/mysql/Driver
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Unknown Source)
    org.apache.jsp.login_jsp._jspService(login_jsp.jav a:88)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)



    Need assistance asap

    ps: If u find out errors in the syntax, do mention them. Though should i admit, some of them have been left intentionally since the mysql connection is the bigger issue at the moment
    Last edited by megabull; 08-30-2012 at 11:48 AM.

  2. #2
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default Re: MySql not connecting to Eclipse even after manually including

    ps: tried org.gjt.mm.mysql.Driver as well as com.mysql.jdbc.Driver , nothing helped [:(]

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    Java Code:
    Class.forName("WEB-INF/lib/org/gjt/mm/mysql/Driver")
    what's that WEB-INF/lib stuff doing in there?
    And that should be a classname (including package) and not a path.

    Oh, and that's not needed anymore with a modern Java (post 1.5 something?)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    How to execute mysql command from text file

    Will you need to be reminded about the code tags in every thread you start?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default Re: MySql not connecting to Eclipse even after manually including

    @Tolls : I had read on a forum where somebody had suggested me. Should i mention, i had initially used the classname as mentioned earlier. Though i dint knew about the address declaration post 1.5 thing

    @Darryl : When the jdbc refuses to connect, and shows error on line 24, i dont care of there's an error on line 70. And btw, wht tags are u talking about? If u think that the empty finally is a mistake, kindly note i have already mentioned that "some of them have been left intentionally since the mysql connection is the bigger issue at the moment" and i dint care about other issues. An empty 'finally' doesnt affect much, does it?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    Please don't use txt spk.
    It's not only annoying, but increases the likelihood of something being misinterpreted.

    Class.forName() needs the full class name, which would be org.gjt.mm.mysql.Driver.

    Of course it's generally recommended to use the current name for the Driver, which is com.mysql.jdbc.Driver.

    If you are still getting an error then the jar file is probably not in the lib directory.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    While I'm here I may as well post my usual comment in cases such as this.
    Do not do things like this in JSP page.
    JSPs are for displaying data that has been pulled together by a servlet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default Re: MySql not connecting to Eclipse even after manually including

    @tolls : That was my exact detection. i tried manually including the parameters too,but dint help :( Only after getting frustrated i posted here.

    Well, yes. You're right in suggesting to not to try this manoeuvre with JSP. Well, i was trying to explore the limits. And i have seen people do mysql connections in JSP online. Check

  9. #9
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default Re: MySql not connecting to Eclipse even after manually including

    update: Got it. Was very tricky. had to reinstall mysql J connector , then copy it to the lib folder. Adding to the build path still doesnt help. I wonder what was the problem.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    You didn't mention an IDE.
    Your build is probably simply not taking in all your required libraries, and putting things on the build path (which is really just the classes needed to compile your app and not necessarily required for running) does not mean they should be deployed.
    It all depends on the IDE and how that operates.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    megabull is offline Member
    Join Date
    Aug 2012
    Posts
    22
    Rep Power
    0

    Default Re: MySql not connecting to Eclipse even after manually including

    Eclipse helios 3.1

    And its started giving me problems - again. Am now updating it. Pretty irritated of the mysql drama
    Last edited by megabull; 08-31-2012 at 01:01 PM.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: MySql not connecting to Eclipse even after manually including

    And having said you didn't mention an IDE I now read the thread title...oops.
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Including Recources into a runnable JAR using eclipse
    By Lucas_F98 in forum New To Java
    Replies: 16
    Last Post: 01-13-2012, 11:16 AM
  2. connecting to a mysql db
    By droidus in forum Networking
    Replies: 3
    Last Post: 10-30-2011, 12:43 AM
  3. Connecting Mysql with J2ME
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 05-22-2011, 10:40 PM
  4. Connecting a MySQL DB through Eclipse
    By mitty in forum New To Java
    Replies: 3
    Last Post: 02-01-2010, 09:22 AM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •