Where is the rest of the code? The code snippet that you included doesn't
output anything.
The error is probably somewhere else in the file.
A few observations on your code:
1) You should learn about using custom tag libraries. The JSP page would
be much cleaner if you used the dbtags library
(http://jakarta.apache.org/taglibs/doc/dbtags-doc/)
2) You should not be declaring your variables in <%! %>. Doing this causes
the variables to be class variables and this will cause concurrency
problems when two requests come to the server at the same time. (IE. Since
there is only one connection, all of the requests will be sharing the same
connection and the result sets may get mixed.) I'd suggest trying to openi
and close the connection for each request and see how that goes. If the
performance is too slow, then try using a connection pool.
3) Another approach would be to put the SQL code in a JavaBean.
Regards,
Richard
At 10:14 AM 9/17/01 +0800, you wrote:
>Dear all,
>
>Please tell me why if the result is no record, then the following error
>message display ? How can I solve it.
>Thanks.
>
>
><%@ page language="java" import="java.sql.*,java.io.*" %>
>
><%!
> Connection con=null;
>
> Statement stmt=null;
> ResultSet result=null;
>
> Statement stmt1=null;
> ResultSet result_Category;
>
> Statement stmt2=null;
> ResultSet result_MemoryCode;
>
> Statement stmt3=null;
> ResultSet result_Brand_Name=null;
>
> Statement stmt4=null;
> ResultSet result_Supplier=null;
>
> // Initialize the connection
> public void jspInit() {
> try {
> DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver()
>);
> con=DriverManager.getConnection("jdbc:oracle:thin:
>@192.168.0.253:1521:aft", "system", "manager" );
> stmt=con.createStatement();
> stmt1=con.createStatement();
> stmt2=con.createStatement();
> stmt3=con.createStatement();
> stmt4=con.createStatement();
> } catch (Exception e) {
> System.out.println( e.toString() );
> }
> }
>
> public void jspDestroy() {
> try {
> result.close();
> result_Category.close();
> result_MemoryCode.close();
> result_Brand_Name.close();
> result_Supplier.close();
>
> stmt.close();
> stmt1.close();
> stmt2.close();
> stmt3.close();
> stmt4.close();
>
> con.close();
> } catch (Exception e) {
> System.out.println( e.toString() );
> }
> }
>%>
>
><%
> try {
>
> //Item Master
> String itcode=request.getParameter("itemcode");
> result=stmt.executeQuery("Select * from dick.Item_Master where
>ITEMCODE = '" + itcode + "'");
>
> if ( result.next() ) {
> System.out.println("Access");
>
> //Category Master
> result_Category=stmt1.executeQuery("Select * from
>dick.Category_Master where category = " + "'" + result.getString
>("Category") + "'");
> result_Category.next();
>
> //Memory Code Master
> result_MemoryCode=stmt2.executeQuery("Select * from
>dick.Memory_Code_Master where memory_code = " + "'" + result.getString
>("memory_code") + "'");
> result_MemoryCode.next();
>
> //Brand Name Master
> result_Brand_Name=stmt3.executeQuery("Select * from
>dick.Brand_Name_Master where brand_code = " + "'" + result.getString
>("brand_code") + "'");
> result_Brand_Name.next();
>
> //Supplier Master
> result_Supplier=stmt4.executeQuery("Select * from
>dick.Supplier_Master where supplier_code = " + "'" + result.getString
>("Supplier_Code") + "'");
> result_Supplier.next();
> }
> } catch (Exception e) {
> System.out.println( e.toString() );
> }
>
>
>%>
>
>
>Category <%=result_Category.getString("Description") %>
>Memory Size <%=result_MemoryCode.getString("Description") %>
>Brand Name <%=result_Brand_Name.getString("Description") %>
>Supplier Name <%=result_Supplier.getString("Description") %>
>IC Base <%=result.getString("IC_BASE") %>
>ECC <%=result.getString("ECC") %>
>Speed <%=result.getString("SPEED") %>
>CAS Latency <%=result.getString("CAS_LATENCY") %>
>Config <%=result.getString("CONFIG") %>
>PCB Layer <%=result.getString("PCB_LAYER") %>
>Packing <%=result.getString("PACKING") %>
>
>
>But I got the following error if the record is not found:
>
>Error: 500
>Location: /web/testing01/search.jsp
>Internal Servlet Error:
>javax.servlet.ServletException: Exhausted Resultset
> at
>org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
>
> at testing_00030_00031.
>_0002ftesting_00030_00031_0002fsearch_0002ejspsearch_jsp_135._jspService
>(_0002ftesting_00030_00031_0002fsearch_0002ejspsearch_jsp_135.java:225)
> at
>org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
>
> at
>org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
> at
>org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
> at org.apache.tomcat.core.Handler.service(Handler.java:287)
> at
>org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
> at
>org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
>
> at
>org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
> at
>org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
>
> at
>org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
> at
>org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
> at java.lang.Thread.run(Thread.java:484)
>
>Root cause:
>java.sql.SQLException: Exhausted Resultset
> at
>oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
> at
>oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
> at
>oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
> at
>oracle.jdbc.driver.OracleStatement.prepare_for_new_get(OracleStatement.java:2400)
>
> at
>oracle.jdbc.driver.OracleStatement.getStringValue(OracleStatement.java:2535)
>
> at
>oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:305)
>
> at
>oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1374)
> at testing_00030_00031.
>_0002ftesting_00030_00031_0002fsearch_0002ejspsearch_jsp_135._jspService
>(_0002ftesting_00030_00031_0002fsearch_0002ejspsearch_jsp_135.java:180)
> at
>org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
>
> at
>org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
> at
>org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
>org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
> at org.apache.tomcat.core.Handler.service(Handler.java:287)
> at
>org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
> at
>org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
>
> at
>org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
> at
>org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
>
> at
>org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
> at
>org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
> at java.lang.Thread.run(Thread.java:484)
>
>===========================================================================
>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