This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes error while using two resultset object in jsp page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "error while using two resultset object in jsp page." Watch "error while using two resultset object in jsp page." New topic
Author

error while using two resultset object in jsp page.

Omkar G. Deshmukh
Ranch Hand

Joined: Sep 21, 2012
Posts: 41


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<%
String a=request.getParameter("msg");
String s="";
String str1="";

Connection con=null;
Statement smt=null;
Statement smt1=null;
ResultSet rs1=null;
ResultSet rs2=null;

try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:MyNewProjectDsn");
smt= con.createStatement();
//smt1= con.createStatement();
rs1= smt.executeQuery("select * from empregtbl where e_login='"+a+"'");

while(rs1.next())
{
str1= rs1.getString(21);


rs2= smt.executeQuery("select * from compadd where Reg_id='"+str1+"'");

if(rs2.next())
{%>

<center><b><font size="5">
<table cellspacing="10">

<tr>
<td align="left" bgcolor="gray"> Registraion Id     </td><td align="right" bgcolor="pink"><%=rs2.getString(1)%></td>

</tr>


<tr>
<td align="left" bgcolor="gray"> First Name     </td><td align="right" bgcolor="pink"><%=rs2.getString(2)%></td>

</tr>


<tr>
<td align="left" bgcolor="gray">Last Name     </td><td align="right" bgcolor="pink"><%=rs2.getString(3)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">DOB     </td><td align="right" bgcolor="pink"><%=rs2.getString(4)%>/<%=rs2.getString(5)%>/<%=rs2.getString(6)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Pan Card No     </td><td align="right" bgcolor="pink"><%=rs2.getString(7)%></td>

</tr>



<tr>
<td align="left" bgcolor="gray">Qualification     </td>
<td align="right" bgcolor="pink">
<%=rs2.getString(8)%>
</td>

</tr>



<tr>
<td align="left" bgcolor="gray">Year Of Completion     </td><td align="right" bgcolor="pink"><%=rs2.getString(9)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Experience     </td><td align="right" bgcolor="pink"><%=rs2.getString(10)%> Yr</td>
</tr>

<tr>
<td align="left" bgcolor="gray">Current Company Name     </td><td align="right" bgcolor="pink"><%=rs2.getString(11)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Previous Company Name     </td><td align="right" bgcolor="pink" ><%=rs2.getString(12)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Current Position     </td><td align="right" bgcolor="pink"><%=rs2.getString(13)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Signed Bond Of     </td><td align="right" bgcolor="pink"><%=rs2.getString(14)%> Yr</td>

</tr>

<tr>
<td align="left" bgcolor="gray">Current Package     </td><td align="right" bgcolor="pink"><%=rs2.getString(15)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">DOJ     </td><td align="right" bgcolor="pink"><%=rs2.getString(16)%>/<%=rs2.getString(17)%>/<%=rs2.getString(18)%></td>

</tr>



<tr>
<td align="left" bgcolor="gray">Phone No     </td><td align="right" bgcolor="pink"><%=rs2.getString(19)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Email Id     </td><td align="right" bgcolor="pink"><%=rs2.getString(20)%></td>

</tr>


<tr>
<td align="left" bgcolor="gray">Address     </td><td align="right" bgcolor="pink"><%=rs2.getString(21)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Pin Code     </td><td align="right" bgcolor="pink"><%=rs2.getString(22)%></td>

</tr>



<tr>
<td align="left" bgcolor="gray">City     </td><td align="right" bgcolor="pink"> <%=rs2.getString(23)%> </td>



</tr>

<tr>
<td align="left" bgcolor="gray">State     </td><td align="right" bgcolor="pink"><%=rs2.getString(24)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Country     </td><td align="right" bgcolor="pink"><%=rs2.getString(25)%></td>

</tr>

</table>
</font>
</b>
</center>


<% }

else
{%>

<center><b><font size="5">
<table cellspacing="10">




<tr>
<td align="left" bgcolor="gray"> First Name     </td><td align="right" bgcolor="pink"><%=rs1.getString(1)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Middle Name:     </td><td align="right" bgcolor="pink"><%=rs1.getString(2)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Last Name     </td><td align="right" bgcolor="pink"><%=rs1.getString(3)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">DOB     </td><td align="right" bgcolor="pink"><%=rs1.getString(4)%>/<%=rs1.getString(5)%>/<%=rs1.getString(6)%></td>

</tr>


<tr>
<td align="left" bgcolor="gray">Gender:     </td><td align="right" bgcolor="pink"><%=rs1.getString(7)%></td>
</tr>

<tr>
<td align="left" bgcolor="gray">Pan Card No     </td><td align="right" bgcolor="pink"><%=rs1.getString(8)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Qualification:     </td><td align="right" bgcolor="pink"><%=rs1.getString(11)%></td>
</tr>

<tr>
<td align="left" bgcolor="gray">Percetage:     </td><td align="right" bgcolor="pink"><%=rs1.getString(12)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Year Of Completion:     </td><td align="right" bgcolor="pink"><%=rs1.getString(13)%></td>
</tr>

<tr>
<td align="left" bgcolor="gray">Experience     </td><td align="right" bgcolor="pink"><%=rs1.getString(14)%> Yr</td>
</tr>

<tr>
<td align="left" bgcolor="gray">Phone No     </td><td align="right" bgcolor="pink"><%=rs1.getString(15)%></td>

</tr>




<tr>
<td align="left" bgcolor="gray">Address     </td><td align="right" bgcolor="pink"><%=rs1.getString(16)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Pin Code     </td><td align="right" bgcolor="pink"><%=rs1.getString(17)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">City     </td><td align="right" bgcolor="pink"> <%=rs1.getString(18)%> </td>



</tr>

<tr>
<td align="left" bgcolor="gray">State     </td><td align="right" bgcolor="pink"><%=rs1.getString(19)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Country     </td><td align="right" bgcolor="pink"><%=rs1.getString(20)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray"> Registraion Id     </td><td align="right" bgcolor="pink"><%=rs1.getString(21)%></td>

</tr>

<tr>
<td align="left" bgcolor="gray">Email Id:     </td><td align="right" bgcolor="pink"><%=rs1.getString(22)%></td>

</tr>




</table>
</font>
</b>
</center>

<% }
}
}

catch (Exception exc) {
out.println(exc);
exc.getMessage();
}


finally
{
con.close();
smt.close();


}
%>


</body>
</html>







error-------

java.sql.SQLException: ResultSet is closed
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

Step 1: Refactor so that all the Java code is in a model class. JSPs should not be doing any Java code, and certainly not DB access code.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Have you checked out Aspose?
 
subject: error while using two resultset object in jsp page.
 
It's not a secret anymore!