I have a Java application which runs MySQL queries in Hibernate.
I am now trying to execute the following MySQL query in hibernate which uses user-defined variables.
I have overcome the issue surrounding ':=' assignments, by adding two backslashes. The compiler is no longer complaining about this, but when I try to execute this query from within my application, it displays the following error message:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREPARE stmt1 from @sql_max; EXECUTE stmt1' at line 1"
My query in Java/hibernate is as follows:
Code:
private static final String COUNT_INTERQUARTILE_SQL
= " SET @sql_max \\:=('SELECT ''Max'' AS quartile, max(visit.id) as id " +
" FROM carecube.visit order by visit.id ');" +
" PREPARE stmt1 from @sql_max;" +
" EXECUTE stmt1;";
Could an experienced Hibernate and/or MySQL expert spot my syntax issues? Thank you all for your help!