Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

java.lang.ClassNotFoundException

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");


 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eduardo ,

please post complete JDBC code , query statement used to DB ?
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
desktop.JPG
[Thumbnail for desktop.JPG]
screenshot
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IVE figured out the problem... thank you for your help!!
 
Would you like to try a free sample? Today we are featuring tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic