[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP Java Compile Error

Posted on 2011-05-11
3
Medium Priority
?
418 Views
Last Modified: 2012-08-13
Hey i'm quite new to jsp and java i am trying to connect to a database and retrieve the contents

 
<table>
Hello!  The time is now <%= new java.util.Date() %>
	<%@ page import="java.util.*" %>
	<%@ page import="javax.sql.*;" %>
	<%@ page import="java.sql.*;" %>
	<%@ page import="sun.jdbc.*;" %>
	<%
	    java.sql.Connection con;
		java.sql.Statement s;
		java.sql.ResultSet rs;
		java.sql.PreparedStatement pst;

	try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	

		} catch(java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException: ");
			System.err.println(e.getMessage());
		}

		try {
		   con = DriverManager.getConnection(url, user, pass);
		} catch(SQLException ex) {
			System.err.println("SQLException: " + ex.getMessage());
		}
	String sql = "";
	try{
		s = con.createStatement();
		rs = s.executeQuery(sql);
	%>

	<%
	while( rs.next() ){
	%><tr>
	<td><%= rs.getString("column_name") %></td>
	<td><%= rs.getString("column_name") %></td>
	<td><%= rs.getString("column_name") %></td>
	<td><%= rs.getString("column_name") %></td>
	</tr>
	<%
	}
	%>

	<%

	}
	catch(Exception e){e.printStackTrace();}
	finally{
		if(rs!=null) rs.close();
		if(s!=null) s.close();
		if(con!=null) con.close();
	}

	%>
</table>

Open in new window


and this is the error i get i can't figure out whats wrong can someone help me?

 
HTTP Status 500 -

type Exception report

message

description 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: 7 in the generated java file
Syntax error on token ";", delete this token

An error occurred at line: 8 in the generated java file
Syntax error on token ";", delete this token

Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.11 logs.
Apache Tomcat/7.0.11

Open in new window

0
Comment
Question by:georgeissac
3 Comments
 
LVL 9

Accepted Solution

by:
ioanton earned 2000 total points
ID: 35741396
>>>>>>>
      <%@ page import="javax.sql.*;" %>
      <%@ page import="java.sql.*;" %>
      <%@ page import="sun.jdbc.*;" %>
>>>>>>

Remove the ; at the end of each directive
0
 

Author Closing Comment

by:georgeissac
ID: 35741406
oh wow that was fast thanks!!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35741422

YOu shoul dnot have ; in page import lines

<%@ page import="java.util.*, java.lang.*" %>
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question