wood burning stoves*
The moose likes JDBC and the fly likes java.lang.ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.ClassNotFoundException" Watch "java.lang.ClassNotFoundException" New topic
Author

java.lang.ClassNotFoundException

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I cant seem to get my JDBC driver to connect to my postgress database...obviously the .jars have been added to my library.
Can anyone help!!

this is the error I am getting

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: org.postgresql.Driver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


and this is what i have in my code!!
Connection connection = null;
Class.forName("org.postgresql.Driver").newInstance();

connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Leads","postgres","sicomedu");


Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Eduardo,



this clearly shows the org.postgresql.Driver class ( available in jar) is not in CLASSPATH. Is it standalone , or available in any server ?

If standalone apps , put jar in CLASSPATH
if available in app/web server , put jar in webapp lib directory
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
Balu,
Thank you, i eventually figured that one, but after adding the JDBC to my library folder i encounter this error...and i truly have no idea how to tackle that...

org.apache.jasper.JasperException: javax.servlet.ServletException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.login_002dprocess_jsp._jspService(login_002dprocess_jsp.java:148)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:235)
org.apache.jsp.login_002dprocess_jsp._jspService(login_002dprocess_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Eduardo ,

please post complete JDBC code , query statement used to DB ?
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
here it is... It is basically a login process page where i get the input from a previous page, name and password, search the database and let the user in or not...

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

<jsp:useBean id="login" class="loginData.LoginData" scope="session"/>
<jsp:setProperty name="login" property="*"/>
<%

Connection connection = null;
Class.forName("org.postgresql.Driver").newInstance();

connection =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/Leads","postgres","sicomedu");

Statement stmt = connection.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM User WHERE User.Name='"+
login.getUsername()+"' AND User.Password ='"+login.getPassword()+"';");

ResultSetMetaData metadata = result.getMetaData();
int numcols = metadata.getColumnCount();
%>
<%

response.setHeader("Cache-Control","no-cache");

/* check the login and password
normally one might want to look the info up in a database instead of
hardcoding it here */
if ( result.next() ) {
/* successful login - set the session attribute "authenticated" so
the secret pages know the login was successful */
session.setAttribute("authenticated","true");
/* figure out where to return to, and remove the attribute from the
session because we don't need it any more */
String target = (String)session.getAttribute("target");
session.removeAttribute("target");
%>
<!-- for some reason, use jsp:forward to redirect back generates an error,
so we'll do the clumsier method of displaying a link for the user to
click on -->
<html>
<head><title>Successful Login</title></head>
<body>
<p>You have successfully logged in.
Click <a href="hobart.jsp">here</a> to continue.</p>
<%
}
%>

</body>
</html>
<%
else {
%>
<!-- if the login wasn't correct, try login.jsp again with an appropriate
error message -->
<jsp:forward page="login.jsp">
<jsp:param name="message"
value="Invalid username or password. Please try again."/>

</jsp:forward>
<%
}
%>
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I dunno if this helps but when I debug i get this error...Ive included a screen shoot...hope that helps

Source not found for Launcher$AppClassLoader.loadClass(String, boolean) line: not available



[Thumbnail for desktop.JPG]

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
IVE figured out the problem... thank you for your help!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassNotFoundException