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!
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:
- Add Connector
- Select Category Database
- Select Connector definition MySQL
- Next
- give it a name
- Next
- Next
- fill in Database Access Information
- Next
- fill in you query (as above)
- Next
- select Scripting Mode
- Next
- select your ResultSet target (MUST BE type ResultSet) (left hand side)
- Add new target - give variable name of type Boolean (left hand side)
- Click pencil (on new line)
- Select Expression type Script
- give it a name
- 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;
- change Return type to Boolean
- OK
- 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.