This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem loading the class

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 45
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error you are getting?

Change this

to


and move it to top of the jsp.

Hopefully this might help
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still your import statement is not correct


by the way: use code tag instead of quote tag while posting code .
 
Balraj Momi
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic