|
 |
servlets thread: resultset
Message #1 by "Dinesh" <d_ahuja1@r...> on Tue, 6 Mar 2001 12:26:57
|
|
I just saw ur mail today (ofcourse too-late, hope by this time u would've
got the remedy!!). The error "Invalid Cursor State" occurs in ur case as
the second resultset (rs2) doesn't contain any records based on the query
it was created. This is just a logical bug during the 2nd iteration.All u
need to do is to check for that empty resultset, everytime, in order to
escape from this exception. Hope this'll help.
Best wishes,
-Madhu
> hi
>
> i am having two tables. sites and siteupdate. siteupdate having
temperory
> records and sites having final records. i want to insert records from
> temperory table into permanent table. in this i am using two resultset.
> after opening first i am opening second one. the loop is working just
one.
> in second time it is giving invalid cursor state. i m attachig code. so
> please check and let me know the solution.
>
>
>
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.*;
> import java.io.*;
> import java.sql.*;
> import java.net.*;
>
> public class UpdateSearchDatabase extends HttpServlet
> {
> PrintWriter out;
>
> //*****************************************************************
> ******
> // class method: service()
> //*****************************************************************
> ******
> public void service(HttpServletRequest req, HttpServletResponse
> res) throws ServletException, IOException
> {
> try
> {
> //connection to the database
>
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection con = DriverManager.getConnection
> ("jdbc:odbc:index","sa","marsitsol");
> Statement st = con.createStatement();
> ResultSet rs,rs1,rs2;
> out = res.getWriter();
>
> String select1 = "select * from siteupdate";
> rs = st.executeQuery(select1);
> String url,str,del,inst;
> int ra,ra1;
> while(rs.next())
> {
> url = rs.getString("URL");
> out.println(url);
>
> str = "select count(*) from sites where
> url = '" + url + "'";
> rs1 = st.executeQuery(str);
> rs1.next();
> int cnt = rs1.getInt(1);
> if(cnt == 1)
> {
> del = "delete from sites where url
> = '" + url + "'";
> ra = st.executeUpdate(del);
> System.out.println("delete = " +
> ra);
> inst = "insert into sites select *
> from siteupdate where url = '" + url + "'";
> ra1 = st.executeUpdate(inst);
> System.out.println("Insert = " +
> ra1);
> }
> else
> {
> inst = "insert into sites select *
> from siteupdate where url = '" + url + "'";
> ra = st.executeUpdate(inst);
> System.out.println("Insert = " +
> ra);
> }
> rs1.close();
> }
> out.println("<a
> href=http://ibm55/se/default.htm>Main</a>");
> } // end try
> catch (Exception sqle)
> {
> out.println(sqle.toString());
> } // end catch
> } // end service()
> } // end class
>
> thanx
|
|
 |