I'm a begginer java programmer. In my dummy projects I'm using the mysql JDBC 5.17 driver for connect to my database
Today I have a simply query
SELECT * FROM books WHERE idb IN (?)
I have this Array of int:
int[2] idBooks = new int{1,2};
and I would to select the books with the id in idBooks
When I use the API "createArrayOf" the JVM throws on the console this error:
java.sql.SQLFeatureNotSupportedException
I know that my driver not support the "createArrayOf" method, there are other solution for do that?
I hope my question is not trivial :)
Thanks a lot in advance, sorry for my english Thanks to all!!
One possible solution:
Java:
// str_idBooks will be [1, 2]
String str_idBooks = Arrays.toString( idBooks );
You have to replace '[', ' '(spaces), ']' from the string to pass to MySQL query.
MySQL:
If you did not replace the characters as said above, use this statement:
SELECT * FROM books
WHERE FIND_IN_SET( idb,
replace(replace(replace(?,'[',''),']',''),' ','')
) > 0
If you have replaced the characters as said above, use this statement:
SELECT * FROM books
WHERE FIND_IN_SET( idb, ? ) > 0
Use the Prepared Statement to set the parameter as :
pst.setString( 1, str_idBooks );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With