开发者

want access resultset of first query for second query

开发者 https://www.devze.com 2023-04-08 23:35 出处:网络
This is java program for SQL statement. I have two queries. Result of the first query is required for second query.

This is java program for SQL statement. I have two queries. Result of the first query is required for second query.

How do I call it in second query?

These results are values for xml tags.

I need to get first query result for this tag

child1.setAttributeNS(xlink,"xlink:type","");

but this is located in 2nd query and if i try to merge those 2 query I get eror resultset closed.

         while(rs1.next()){
        int i=0,j=0 ,locid,supid;
        int lc[]=new int[100];
        int sp[]=new int[100];
      lc[i] =   rs1.getInt(2);
        sp[j] =   rs1.getInt(1);
        lcid=lc[i++];*/
         for(i=0;i<loc[i];i++){
        for(j=0;j<sup[j];j++){
          lcid=lc[i];  spid=sp[j];
      System.out.print(spid +" ");
       System.out.println(lcid);
  String开发者_开发问答     s = (lc[i]==1 ? "simple" : (lc[i]>1 ? "extended" : null));

         System.out.println(s);            }}}

      String querystring=
          " ";


        rs = stmt.executeQuery(querystring );
   while(rs.next()){
        Element child1 = doc.createElement("slink");

                          /
        Element element = doc.createElement("loc");


You need to create a brand new and separate Statement for the second ResultSet. Everytime you get a new ResultSet out of a single Statement, every previously opened one will namely be closed.

Replace

rs = stmt.executeQuery(querystring );

by

Statement stmt2 = connection.createStatement();
rs = stmt2.executeQuery(querystring);

Don't forget to add stmt2.close() to the finally block.


Unrelated to the concrete problem, have you considered just JOINing the both queries and using Javabeans to represent the model? This way you end up with a single query and more self-documenting code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号