Is there a way to check if there are mysql results or not?

1
0
-1

Hi,

I want to know if is there any way in order to check if there are mysql results or not. I have created a service tasks with a mysql conector. In this conncetor i have implemented this mysql query:

SELECT * FROM documentation WHERE
name_doc='aaaa'
and version_doc='22';

But when i'm trying to check if this works or not, i see this error:

java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.exception.BonitaRuntimeException: USERNAME=install | java.lang.ClassCastException: com.mysql.jdbc.JDBC4ResultSet cannot be cast to java.io.Serializable

What i'm trying to do is , if is truth that there are mysql results, then to assign the true or 1 value to a variable verify if not , then assign the value false or 0.

I really need this.

Thanks in advanced!

1 answer

1
0
-1
This one is the BEST answer!

You're not doing it right that's the problem...

Here you have TWO results and not one. You have the ResultSet and (because you want it) a Boolean variable RecordsAvailable

By the way this is VERY bad practice, normally you would just see if ResultSet is empty or not rather than see if has records and then set another variable to verified

Anyway:

In your Connector (I assume you are using Database Connector and not Script Connector) you have to do the following:

  1. Add Connector
  2. Select Category Database
  3. Select Connector definition MySQL
  4. Next
  5. give it a name
  6. Next
  7. Next
  8. fill in Database Access Information
  9. Next
  10. fill in you query (as above)
  11. Next
  12. select Scripting Mode
  13. Next
  14. select your ResultSet target (MUST BE type ResultSet) (left hand side)
  15. Add new target - give variable name of type Boolean (left hand side)
  16. Click pencil (on new line)
  17. Select Expression type Script
  18. give it a name
  19. In the code section add
//set for no records
def areThereRecords = false;
while(resultset.next()){
       //return true if even one record
        areThereRecords = true;
        break;
}
return areThereRecords;
  1. change Return type to Boolean
  2. OK
  3. Finish

There you have it a record set that can be null or with records, and a variable that says if there are records or not.

All done except the testing - I'll leave that to you

regards
Seán

PS: If this reply answers your question, please mark as resolved.

Notifications