This code isn't OK at all!!!
Still the same remarkls:
- It's absolutely NOT thread safe. Avoid using <%! %> tags.
- Exception handling has a meaning. Never do
catch (SQLException e){ }
- Close the Resultset, statements and Connections properly!!!
Geert Van Damme
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Sachin S. Khanna
> Sent: vrijdag 18 mei 2001 13:03
> To: [EMAIL PROTECTED]
> Subject:
>
>
> Find the modified jsp and bean files below :
> They are working :-)
> bean file :
>
> mport java.sql.*;
> import java.util.*;
>
> public class databank {
>
> private String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
> private String url = "jdbc:odbc:db1";
> private Connection connection;
> private Statement statement;
> private ResultSet res;
> private ResultSetMetaData meta;
> private String naam;
> private int aantal;
>
> public databank(){}
>
> public ResultSet lijst(){
> try {
> String query = "select * from klant";
> Class.forName(driver);
> connection = DriverManager.getConnection(url);
> statement = connection.createStatement();
> res = statement.executeQuery(query);
> }
> catch (SQLException e){
> }
> catch (ClassNotFoundException cnfex){}
>
> return res;
> }
> }
> ------------------------------
> jsp file
>
> html>
> <body>
>
> <%@ page import="databank" %>
> <%@ page import="java.sql.*" %>
>
> <jsp:useBean id="db" class="databank" />
>
> <%! ResultSet res;
> ResultSetMetaData meta;
> int aantal;
> int kol;
> %>
>
> <% res = db.lijst();
> %>
>
> <% if(!res.next()) {
> System.out.println("Reached here again");
> out.println("Deze instructie heeft geen resultaten");
> }
> else
>
> res.next();
> %>
> <%= res.getString(0) %>
> <% } %>
>
>
> </body>
> </html>
>
>
>
> Have a nice day.
> With regards,
> Sachin S. Khanna
> http://www.emailanorder.com
> ----- Original Message -----
> From: Jonas Devries <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, May 18, 2001 3:14 PM
>
>
> > This is the whole jsp-file!!!
> >
> > Hope you can do something with it!!
> >
> > Thanx
> > Jonas
> >
> > <html>
> > <body>
> >
> > <%@ page import="databank" import="java.sql.*" %>
> >
> > <jsp:useBean id="db" class="databank" />
> >
> > <%! ResultSet res;
> > ResultSetMetaData meta;
> > int aantal;
> > int kol;
> > %>
> >
> > <% res = db.lijst("select * from klant"); %>
> >
> > <% if(!res.next()) {
> > out.println("Deze instructie heeft geen resultaten");
> > }
> > else { %>
> > <%= res.getString(0) %>
> > <% } %>
> >
> >
> > </body>
> > </html>
> >
> >
> > >From: "Sachin S. Khanna" <[EMAIL PROTECTED]>
> > >Reply-To: A mailing list about Java Server Pages specification and
> > > reference <[EMAIL PROTECTED]>
> > >To: [EMAIL PROTECTED]
> > >Date: Fri, 18 May 2001 14:37:47 +0530
> > >
> > >Couple of things :
> > >a) Provide the complete source code for the jsp.
> > >b) Apparently nothing seems to be wrong with your java bean code.
> > >Have a nice day.
> > >With regards,
> > >Sachin S. Khanna
> > >http://www.emailanorder.com
> > >----- Original Message -----
> > >From: Jonas Devries <[EMAIL PROTECTED]>
> > >To: <[EMAIL PROTECTED]>
> > >Sent: Friday, May 18, 2001 1:04 PM
> > >
> > >
> > > > Does somebody knows why this code doesn't work? I want to
> acces a MS
> =
> > > > Access DB and give a simple query. I give the ResultSet back to my
> JSP
> > >=
> > > > file but he gives some errors. JSP and Java-bean are included.
> Errors
> > >=
> > > > also. There is data in the db and the odbc-jdbc driver is
> installed.
> > > >
> > > > Thank you very much in advance
> > > >
> > > > Jonas
> > > >
> > > >
> > > > import java.sql.*;
> > > > import java.util.*;
> > > >
> > > > public class databank {
> > > >
> > > > private String driver =3D "sun.jdbc.odbc.Jdbc.OdbcDriver";
> > > > private String url =3D "jdbc:odbc:db1";
> > > > private Connection connection;
> > > > private Statement statement;
> > > > private ResultSet res;
> > > > private ResultSetMetaData meta;
> > > > private String naam;
> > > > private int aantal;
> > > >
> > > > public databank(){}
> > > > =20
> > > > =20
> > > > public ResultSet lijst(){
> > > >
> > > > try {
> > > > String query =3D "select * from klant";
> > > > Class.forName(driver);
> > > > connection =3D DriverManager.getConnection(url); =20
> > > > statement =3D connection.createStatement();
> > > > res =3D statement.executeQuery(query); =20
> > > > =20
> > > > }
> > > > catch (SQLException e){}
> > > > catch (ClassNotFoundException cnfex){}=20
> > > >
> > > > return res;
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > > ResultSetMetaData meta =3D res.getMetaData(); int aantal =3D
> > > > meta.getColumnCount(); %> while (res.next()){ for (kol =3D
> 1; kol <=3D
> > > > aantal; kol++) %>
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Error: 500
> > > > Location: /test9.jsp
> > > > Internal Servlet Error:
> > > >
> > > > javax.servlet.ServletException
> > > > at =
> > > >
> >
> >org.apache.jasper.runtime.PageContextImpl.handlePageException(Pag
> eContext=
> > > > Impl.java:386)
> > > > at =
> > > >
> >
> >_0002ftest_00039_0002ejsptest9_jsp_0._jspService(_0002ftest_00039
> _0002ejs=
> > > > ptest9_jsp_0.java:126)
> > > > at
> > >org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
> > > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > > > at =
> > > >
> >
> >org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(Js
> pServlet=
> > > > .java:174)
> > > > at =
> > > >
> org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
> > > > at
> > >org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
> > > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > > > at =
> > > >
> >
> >org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrappe
> r.java:5=
> > > > 03)
> > > > at =
> > > >
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
> > > > at =
> > > >
> >
> >org.apache.tomcat.service.connector.Ajp12ConnectionHandler.proces
> sConnect=
> > > > ion(Ajp12ConnectionHandler.java:156)
> > > > at =
> > > >
> >
> >org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoi
> nt.java:=
> > > > 338)
> > > > at java.lang.Thread.run(Thread.java:484)
> > > >
> > > > Root cause:=20
> > > > java.lang.NullPointerException
> > > > at =
> > > >
> >
> >_0002ftest_00039_0002ejsptest9_jsp_0._jspService(_0002ftest_00039
> _0002ejs=
> > > > ptest9_jsp_0.java:93)
> > > > at
> > >org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
> > > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > > > at =
> > > >
> >
> >org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(Js
> pServlet=
> > > > .java:174)
> > > > at =
> > > >
> org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
> > > > at
> > >org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
> > > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > > > at =
> > > >
> >
> >org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrappe
> r.java:5=
> > > > 03)
> > > > at =
> > > >
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
> > > > at =
> > > >
> >
> >org.apache.tomcat.service.connector.Ajp12ConnectionHandler.proces
> sConnect=
> > > > ion(Ajp12ConnectionHandler.java:156)
> > > > at =
> > > >
> >
> >org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoi
> nt.java:=
> > > > 338)
> > > > at java.lang.Thread.run(Thread.java:484)
> > > >
> > > >
> > > >
> >
> >_________________________________________________________________________
> > > > Get Your Private, Free E-mail from MSN Hotmail at
> > >http://www.hotmail.com.
> > > >
> > > >
> >
> >=================================================================
> ==========
> > > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > >JSP-INTEREST".
> > > > For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST
> > >DIGEST".
> > > > Some relevant FAQs on JSP/Servlets can be found at:
> > > >
> > > > http://java.sun.com/products/jsp/faq.html
> > > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> > > >
> > >
> >
> >=================================================================
> ==========
> > >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > >JSP-INTEREST".
> > >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> > >DIGEST".
> > >Some relevant FAQs on JSP/Servlets can be found at:
> > >
> > > http://java.sun.com/products/jsp/faq.html
> > > http://www.esperanto.org.nz/jsp/jspfaq.html
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
> >
> _________________________________________________________________________
> > Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets