Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > PLEASE HELP at Java Servlet / Java Server Pages !!!!!

Reply
Thread Tools

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

 
 
nowy84@gmail.com
Guest
Posts: n/a
 
      06-25-2006
// 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("j dbc:
oracle:thin//localhost:3306/"baza","login","haslo");
java.sql.ResultSet rs=connection.createStatement().executeQuery("sele ct
* 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.servic e(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.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.jav acError(DefaultErrorHandler.
java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:32
org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:297)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:276)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:264)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.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.

 
Reply With Quote
 
 
 
 
TM
Guest
Posts: n/a
 
      06-25-2006

wrote:
> // 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("j dbc:
> oracle:thin//localhost:3306/"baza","login","haslo");
> java.sql.ResultSet rs=connection.createStatement().executeQuery("sele ct
> * 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.servic e(JspServletWrapper.java:375)
> org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
> org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.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.jav acError(DefaultErrorHandler.
> java:84)
> org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:32
> org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:414)
> org.apache.jasper.compiler.Compiler.compile(Compil er.java:297)
> org.apache.jasper.compiler.Compiler.compile(Compil er.java:276)
> org.apache.jasper.compiler.Compiler.compile(Compil er.java:264)
> org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:563)
> org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:303)
> org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
> org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.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("j dbcracle:thin:<username>/<pass>@<host>:<port>e");

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();
}


}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.net 2 Master pages menu and saving pages - Weired situation - please help Annie ASP .Net 4 04-24-2007 12:16 PM
Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response javadev Java 5 11-16-2006 11:22 AM
servlet help - redirecting from within a framed servlet ppcguy Java 1 08-08-2005 03:03 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57