Results 1 to 12 of 12
- 08-30-2012, 11:42 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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 momentLast edited by megabull; 08-30-2012 at 11:48 AM.
- 08-30-2012, 12:46 PM #2
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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 [:(]
- 08-30-2012, 02:34 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: MySql not connecting to Eclipse even after manually including
what's that WEB-INF/lib stuff doing in there?Java Code:Class.forName("WEB-INF/lib/org/gjt/mm/mysql/Driver")
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.
- 08-30-2012, 03:05 PM #4
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-30-2012, 05:01 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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?
- 08-30-2012, 05:55 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 08-30-2012, 05:56 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 08-31-2012, 06:16 AM #8
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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
- 08-31-2012, 08:27 AM #9
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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.
- 08-31-2012, 10:02 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 08-31-2012, 12:49 PM #11
Member
- Join Date
- Aug 2012
- Posts
- 22
- Rep Power
- 0
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 dramaLast edited by megabull; 08-31-2012 at 01:01 PM.
- 08-31-2012, 01:35 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Including Recources into a runnable JAR using eclipse
By Lucas_F98 in forum New To JavaReplies: 16Last Post: 01-13-2012, 11:16 AM -
connecting to a mysql db
By droidus in forum NetworkingReplies: 3Last Post: 10-30-2011, 12:43 AM -
Connecting Mysql with J2ME
By razmyasdfg in forum CLDC and MIDPReplies: 2Last Post: 05-22-2011, 10:40 PM -
Connecting a MySQL DB through Eclipse
By mitty in forum New To JavaReplies: 3Last Post: 02-01-2010, 09:22 AM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks