Hello Leander,

Thank you very much for your enquiry.

In order to run several statements in one statement by the MySQL JDBC
connector, you'll have to specify the allowMultiQueries=true JDBC URL
parameter as documented here:
https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

Another option would be to parse the file and split the statements into
individual statements, and run them either one by one, or as a JDBC batch.
Splitting is not trivial, of course, because a semi-colon in the SQL file
might not be a statement terminator, but a value in a string literal, or a
statement terminator inside of a stored procedure.

Hope this helps,
Lukas

2016-01-24 18:41 GMT+01:00 Leander Kurscheidt <[email protected]>
:

> Hello,
> i have a file containing all the statements needed to create the database:
>
> this is roughly my code:
>
> try (InputStream in = DatabaseManager.class.getResourceAsStream("/db.sql")) {
>     String initScript = IOUtils.toString(in, "UTF-8");
>
>     context.execute(initScript);
>
> .....
>
>
> but i always get an exception:
> Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'USE `..` ;
>
> the script works in the mysql-workbench, so it should not be his fault.
> Since this is pretty trivial code i don`t know what i am doing wrong.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to