Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4329779

PreparedStatement only executing the second select statement

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.8
    • core-libs
    • x86
    • windows_nt



      Name: stC104175 Date: 04/12/2000


      java version "1.1.8"

      /**********************
      * Sample code
      ***********************/

      void static main(String args[]) {

      // type 2 driver
      String url = "jdbc:db2:dataSource";

      try {
           Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
      } catch ( Exception e ) {
           System.out.println("Cannot load database driver");
           return;
      }

      try {
           Connection con = DriverManager.getConnection(url, args[0], args[1]);
           PreparedStatement prepStatement = con.prepareStatement(
               "SELECT * FROM Company_Employee WHERE UserName = ?;
                SELECT * FROM Division_Employee WHERE UserName = ?");

           prepStatement.setString(1, "JSMITH");
           prepStatement.setString(2, "EWAGNER");

           boolean isResult = prepStatement.execute();

           while ( isResult ) {

                ResultSet resultSet = prepStatement.getResultSet();

                // dislplay the contents of the result set
      printResultSet("", resultSet );

      isResult = prepStatement.getMoreResults();
           }

           prepStatement.clearParameters();

           prepStatement.setString(1, "HWELLINGON");
           prepStatement.setString(2, "AJONES");

           isResult = prepStatement.execute();

           while ( isResult ) {

                ResultSet resultSet = prepStatement.getResultSet();

                // display the contents of the resultSet
      printResultSet("", resultSet );

      isResult = prepStatement.getMoreResults();
           }

           prepStatement.close();
           prepStatement = null;

           con.rollback();
           con.close();
           con = null;

      } catch (Exception e) {

           e.printStackTrace();
      }
      }

      /****************************
      * End of Sample Code
      *****************************/

      This code produces the problem of the prepared statement only executing
      the second select statement when it is executed the second time. I would expect
      both select statements to be executed when the prepared statment is executed.
      (Review ID: 103402)
      ======================================================================

            jellissunw Jon Ellis (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: