Thursday, December 1, 2011

Setting MySQL to Allow Multiple Statements In a Single Query In JDBC/OpenBD

This came up in a discussion on the OpenBD Google Group today so I figured it was worth a quick blog post.

Depending on what you're doing with MySQL you may be in a situation where you need to run multiple SQL statements separated by a ; as part of a single query. By default this isn't enabled in the JDBC connection with MySQL, but it's easy to enable in your JDBC connection string.

When creating a MySQL datasource in the OpenBD admin, click on the "Advanced Settings" button, and in the "Connection String" box input the following text:

If you're creating the datasource for the first time this will be all you need to do, but if you're adding this to an existing datasource you'll want to bounce OpenBD to make sure the connection pool is cleared out.

To test that the setting change worked, simply write a CFQUERY that contains two statements:
<cfquery name="foo" datasource="foo">

If that doesn't throw an error, then you're all set to run multiple statements in the same CFQUERY tag.
Note that you can enable this setting in bluedragon.xml as well, just make sure your <connectstring> node for your datasource looks like this:

And your <hoststring> node should look something like this:

No comments: