JSP Java Compile Error

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

georgeissacAsked:
Who is Participating?
 
ioantonConnect With a Mentor Commented:
>>>>>>>
      <%@ page import="javax.sql.*;" %>
      <%@ page import="java.sql.*;" %>
      <%@ page import="sun.jdbc.*;" %>
>>>>>>

Remove the ; at the end of each directive
0
 
georgeissacAuthor Commented:
oh wow that was fast thanks!!
0
 
for_yanCommented:

YOu shoul dnot have ; in page import lines

<%@ page import="java.util.*, java.lang.*" %>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.