Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
nowy84@gmail.com - 25 Jun 2006 19:57 GMT
// 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.
TM - 25 Jun 2006 22:58 GMT
> // Forgive my English :)
> I have to write a program (JS or JSP), which connect with Oracle and
[quoted text clipped - 68 lines]
> 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:oracle: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();
   }
   

}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.