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

Discussion in 'Java' started by nowy84@gmail.com, Jun 25, 2006.

  1. Guest

    // 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.
     
    , Jun 25, 2006
    #1
    1. Advertising

  2. TM Guest

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


    }
     
    TM, Jun 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    2,015
    Jack Jia
    Apr 4, 2004
  2. Replies:
    4
    Views:
    520
    Chris Uppal
    May 5, 2005
  3. ppcguy
    Replies:
    1
    Views:
    610
    Andrea Desole
    Aug 8, 2005
  4. KK
    Replies:
    2
    Views:
    592
    Big Brian
    Oct 14, 2003
  5. Annie
    Replies:
    4
    Views:
    702
    Annie
    Apr 24, 2007
Loading...

Share This Page