Menu

Insert not returning boolean?

2008-09-23
2013-04-15
  • Nobody/Anonymous

    Hi

    I'm using MockRunner to test some DB code and I'm very pleased with the way it works.

    But I have a problem when I try to test an INSERT INTO statement.

    PreparedStatement statement = null;

    ...

    statement = getPreparedStatement(TUL0060.getInsertIntoSql());

    ...

    return statement.execute();

    My code expect a true boolean result from the 'statement.execute()' but I always get a false.

    I can't seem to find any examples on how to set this up?

    Best regards

    Thomas

     
    • Alwin Ibba

      Alwin Ibba - 2008-09-23

      PreparedStatement.execute() "Returns true if the first result is a ResultSet object; false if the first result is an update count or there is no result" (quote from JavaDoc).

      Mockrunner expects that queries (select) return a ResultSet and inserts/updates return an update count.

      You can specify that any SQL you like returns a ResultSet with AbstractResultSetHandler.prepareReturnsResultSet(...). Then you'll get true for the execute call.

      Kind regards,

      Alwin

       
    • Nobody/Anonymous

      Thanks

      Couldn't get it to work yesterday - but it works today! ;o)

      // Thomas

       
  • Nobody/Anonymous

    prepareReturnsResultSet("UPDATE MUREXDB.MKV_SYB SET MUREX_STATUS = ? WHERE MKV_ID = ?",false);
            statement =connection.prepareStatement("UPDATE MUREXDB.MKV_SYB SET MUREX_STATUS = ? WHERE MKV_ID = ?");
            statement.setInt(1,3);
            statement.setInt(2,12);
            boolean flag=statement.execute();
            System.out.println("Flag "+flag);

    Still flag is false

     

Log in to post a comment.