aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem loading the class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem loading the class" Watch "Problem loading the class" New topic
Author

Problem loading the class

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187

HEY I WROTE THIS CODE and i am getting the following error.
i am not understanding what the error is..i m trying to connect to my database and display the values of the table...
Balraj Momi
Ranch Hand

Joined: Jul 23, 2009
Posts: 45

What error you are getting?

Change this

to


and move it to top of the jsp.

Hopefully this might help


Regards
Balraj Kumar
SCJP 5 95%
SCWCD 82%
Preparing for SCBCD
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
i made changes but i m still getting errors in the code..


the errors are as follows:
The server encountered an internal error () that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. java.sql resolves to a package

An error occurred at line: 7 in the jsp file: /sql1.jsp
Connection cannot be resolved to a type
4: <%@ page import="java.sql,com.conn.*,java.sql.ResultSet" %>
5: <%
6: String url = "jdbc:postgresql://localhost/Books";
7: Connection con;
8: ResultSet rs;
9: String s;
10: Statement st;


An error occurred at line: 10 in the jsp file: /sql1.jsp
Statement cannot be resolved to a type
7: Connection con;
8: ResultSet rs;
9: String s;
10: Statement st;
11: String sqlstr = "SELECT \"ID\",\"Book Name\",\"Author\" FROM public.books_details";
12:
13: try


An error occurred at line: 25 in the jsp file: /sql1.jsp
DriverManager cannot be resolved
22:
23: try
24: {
25: con = DriverManager.getConnection(url,"postgres", "admin123");
26:
27: st = con.createStatement();
28: rs = st.executeQuery(sqlstr);


An error occurred at line: 41 in the jsp file: /sql1.jsp
SQLException cannot be resolved to a type
38: con.close();
39:
40: }
41: catch(SQLException ex)
42: {
43: System.err.println("SQLException: " + ex.getMessage());
44: }


An error occurred at line: 43 in the jsp file: /sql1.jsp
ex cannot be resolved
40: }
41: catch(SQLException ex)
42: {
43: System.err.println("SQLException: " + ex.getMessage());
44: }
45:
46:


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

your code is not formatted , it is difficult to read. please edit your post to use code tag to post gain
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 187
The server encountered an internal error () that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. java.sql resolves to a package

An error occurred at line: 7 in the jsp file: /sql1.jsp
Connection cannot be resolved to a type
<%@ page import="java.sql,com.conn.*,java.sql.ResultSet" %>
<%
String url = "jdbc:postgresql://localhost/Books";
Connection con;
ResultSet rs;
String s;
Statement st;


An error occurred at line: 10 in the jsp file: /sql1.jsp
Statement cannot be resolved to a type
Connection con;
ResultSet rs;
String s;
Statement st;
String sqlstr = "SELECT \"ID\",\"Book Name\",\"Author\" FROM public.books_details";

try


An error occurred at line: 25 in the jsp file: /sql1.jsp
DriverManager cannot be resolved

try
{
con = DriverManager.getConnection(url,"postgres", "admin123");

st = con.createStatement();
rs = st.executeQuery(sqlstr);


An error occurred at line: 41 in the jsp file: /sql1.jsp
SQLException cannot be resolved to a type
con.close();

}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}


An error occurred at line: 43 in the jsp file: /sql1.jsp
ex cannot be resolved
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

still your import statement is not correct


by the way: use code tag instead of quote tag while posting code .
Balraj Momi
Ranch Hand

Joined: Jul 23, 2009
Posts: 45

You have to fix your imports, Statement interface is inside java.sql package.
So fix it by by changing it to java.sql.* as below.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem loading the class