PLEASE HELP at Java Servlet / Java Server Pages !!!!!

N

nowy84

// Forgive my English :)
I have to write a program (JS or JSP), which connect with Oracle and
get out date from some table. I've found some example, but it makes
errors :((
I installed these :
J2EE 5.0
Tomcat 5.5.17
Oracle Express Edition 10.2g

I put ojdbc14.jar in in folder, where is my .jsp file.
Source of .jsp :
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
java.sql.Connection
connection=java.sql.DriverManager.getConnection("jdbc:
oracle:thin//localhost:3306/"baza","login","haslo");
java.sql.ResultSet rs=connection.createStatement().executeQuery("select
* from
$TableName");
out.println("col count is "+rs.getMetaData().getColumnCount());
String colName=rs.getMetaData().getColumnLabel(1);
out.println("col label is "+colName);
while(rs.next()){
Object o=rs.getObject(colName);
out.println(colName+" "+o);
}
%>

Errors :
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: 1 in the jsp file: /moja/baza2.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


org.apache.jasper.servlet.JspServletWrapper.
handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

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

An error occurred at line: 1 in the jsp file: /moja/baza2.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.
java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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

TM

// Forgive my English :)
I have to write a program (JS or JSP), which connect with Oracle and
get out date from some table. I've found some example, but it makes
errors :((
I installed these :
J2EE 5.0
Tomcat 5.5.17
Oracle Express Edition 10.2g

I put ojdbc14.jar in in folder, where is my .jsp file.
Source of .jsp :
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
java.sql.Connection
connection=java.sql.DriverManager.getConnection("jdbc:
oracle:thin//localhost:3306/"baza","login","haslo");
java.sql.ResultSet rs=connection.createStatement().executeQuery("select
* from
$TableName");
out.println("col count is "+rs.getMetaData().getColumnCount());
String colName=rs.getMetaData().getColumnLabel(1);
out.println("col label is "+colName);
while(rs.next()){
Object o=rs.getObject(colName);
out.println(colName+" "+o);
}
%>

Errors :
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: 1 in the jsp file: /moja/baza2.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


org.apache.jasper.servlet.JspServletWrapper.
handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

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

An error occurred at line: 1 in the jsp file: /moja/baza2.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.
java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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

I'm not sure that your code is suitable for a JSP. It looks more like
the code you would use for a servlet. There are some Exceptions that
need to be handled as well (ClassNotFound, SQLException).

You should also put your ojdbc14.jar in your applications WEB-INF\lib
folder in tomcat.

If you want to run the statements, you might read up on JSTL tags,
specifically <sql:transaction>. Otherwise, your code is on its way to
working as a servlet so you could always try the servlet first to make
sure your DB connection and drivers are good. Here is the code I ran
on my Tomcat install and it worked though you will want to work on the
formatted output because it doesn't appear to be what you are after.

//be sure to change the connect string
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html;
charset=windows-1252";

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
ResultSet rs;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");

java.sql.Connection
connection=java.sql.DriverManager.getConnection("jdbc:eek:racle:thin:<username>/<pass>@<host>:<port>:xe");

rs = connection.createStatement().executeQuery("select * from
$TableName");
out.println("col count is "+rs.getMetaData().getColumnCount() +
"<br>");
String colName = rs.getMetaData().getColumnLabel(1);
out.println("col label is "+colName);
while(rs.next()){
Object o=rs.getObject(colName);
out.println(colName+" "+o);

}
}catch (SQLException sqle) {

}

catch (Exception e) {


}

out.close();
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top