"Before Start of result Set Exception:" in JSP
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Scott_Decosta
Posted On:   Thursday, May 17, 2001 02:11 PM

Hi there When I try to connect my JSP to my database thru a bean and fetch data from Result set I am getting exception.. My JSP code is like this.. <%@ page import ="tryBean" %> <% String eid=request.getParameter("param1"); tb.setConnection(); ResultSet rs1 = tb.getResultSet(eid); String lname= rs1.getString("lastname"); String fname= rs1.getString("firstname"); String ext = rs1.getString("extension"); String city= rs1.getString("cityofresidence"); String dept= rs1.getString("dept"); %> ----- and in my bean I try to con   More>>

Hi there
When I try to connect my JSP to my database thru a bean and fetch data from Result set I am getting exception..

My JSP code is like this..
<%@ page import ="tryBean" %>




<%
String eid=request.getParameter("param1");
tb.setConnection();
ResultSet rs1 = tb.getResultSet(eid);
String lname= rs1.getString("lastname");
String fname= rs1.getString("firstname");
String ext = rs1.getString("extension");
String city= rs1.getString("cityofresidence");
String dept= rs1.getString("dept");
%>

-----


and in my bean I try to connect to Database to get the required data...
tryBean.java

public void setConnection () {
try {
dbPool = DBPool.getPool("test_db");
con = dbPool.getConnection();
stmt = con.createStatement();
}catch(SQLException e) {
e.getMessage(); }
}

public ResultSet getResultSet(String id) throws Exception {
rs = stmt.executeQuery("SELECT * FROM emp where empid
='"+id+"' " );
return rs;
}

-------
But When I run my JSP I get the following error..
java.sql.SQLException: Before start of result set
at org.gjt.mm.mysql.ResultSet.checkRowPos
(ResultSet.java:1336)
at org.gjt.mm.mysql.ResultSet.getString
(ResultSet.java:220)
at org.gjt.mm.mysql.ResultSet.getString
(ResultSet.java:889)
at _jsp._custModify__jsp._jspService(/custModify.jsp:22)
at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
at com.caucho.jsp.Page.service(Page.java:407)
at com.caucho.server.http.FilterChainPage.doFilter (FilterChainPage.java:136)
at com.caucho.server.http.Invocation.service (Invocation.java:268)
at com.caucho.server.http.CacheInvocation.service (CacheInvocation.java:128)
at com.caucho.server.http.HttpRequest.handleRequest (HttpRequest.java:238)
at com.caucho.server.http.HttpRequest.handleConnection (HttpRequest.java:157)
at com.caucho.server.TcpConnection.run
(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)

This exception is very new to me ...So please help me..
What is the problem in my code..
Thanks
ScottDecosta    <<Less

Re: &quot;Before Start of result Set Exception:&quot; in JSP

Posted By:   Anonymous  
Posted On:   Thursday, May 17, 2001 02:25 PM

In addition to the nice answer from Christopher, I've noticed that your "getResultSet()" method it's not closing the Statement object. I can understand why you are doing it, but I'm afraid that in the long run that can generate problems with your database connection.

Few month ago we had (with Oracle) a "too many cursors" problem because of that.

Regards.

Re: &quot;Before Start of result Set Exception:&quot; in JSP

Posted By:   Christopher_Schultz  
Posted On:   Thursday, May 17, 2001 02:18 PM

Before you call any methods like ResultSet.getXXX(), you must call ResultSet.next() or any other method that moves the 'current' row in a ResultSet.

-chris
About | Sitemap | Contact