MySQL 3/4 - com.mysql.jdbc.Driver And allowMultiQueries=true

Posted March 25, 2009 at 4:20 PM by Ben Nadel

Tags: ColdFusion, SQL

Just a quick note on configuring a MySQL JDBC Driver to allow multiple queries per CFQuery tag when using MySQL 3/4 (pre MySQL 5) on a ColdFusion 8 server. A few months ago, I leaned that you could add "allowMultiQueries=true" to the MySQL 5 connection string. However, today, I had to do some work on a ColdFusion MX 7 box that only had MySQL JDBC driver capabilities. I tried adding the allowMultiQueries to the connection string but this did not work.

After some Googling, I found that you have to add the allowMultiQueries=true to the actual JDBC Url, not the Connection String field:


 
 
 

 
Turning On Multiple Queries Using com.mysql.jdbc.Driver.  
 
 
 

I put that in and it worked nicely.




Reader Comments

Mar 25, 2009 at 4:33 PM // reply »
12 Comments

Make sure your queries are sanitized. Most SQL injection attacks use the ability to do multiple queries per connection.


Mar 25, 2009 at 4:35 PM // reply »
11,246 Comments

@Jules,

Most definitely.


Mar 25, 2009 at 4:35 PM // reply »
8 Comments

This is a setting which would be good to define always.

Depending on some of our projects we had to have on MySQL 5 definition too.

Thanks for sharing ...


Mar 25, 2009 at 9:38 PM // reply »
39 Comments

Maybe this is a dumb question, but I personally liked the thought that it only allowed one query at a time, and because of that much less worry about SQL injection.

Other then the convenience of writing multiple queries in a single cfquery tag, what are the benefits of doing that? A speed boost cause it pack multiple calls to the db into one?

I think it's a neat tip, but I guess I'd need to be convinced on why I'd actually do it.


Mar 25, 2009 at 9:40 PM // reply »
11,246 Comments

@Tim,

My biggest reason for using it is to create a new record and then immediately select the new auto-increment ID created using LAST_INSERT_ID(), or, in newer versions of MySQL, @@Identity.


Mar 26, 2009 at 5:40 AM // reply »
1 Comments

I try to use allowMultiQueries=true as less as possible, hence my default datasource for an application allows only one query at a time. If I need multiple queries for an app I define a second datasource and use it only where needed.

Question: What do folks think about LAST_INSERT_ID() and using it inside 1 cfquery. Is it safe? Or even inside 2 cfquery tags one after another? Would I need <cftransaction> or <cflock type="exclusive"> for that? I am not sure since I heard different opinions on that in the past.


Mar 26, 2009 at 8:25 AM // reply »
12 Comments

@Thilo Hermann,

My opinion on that is, to not use auto incrementing IDs - use UUIDs instead. But I'm sure Mr. Nadel is tired of that discussion =)


Mar 26, 2009 at 8:30 AM // reply »
11,246 Comments

@Thilo,

I have never had a problem with it and I find it to be saver than SELECT MAX(id).


Mar 26, 2009 at 8:30 AM // reply »
11,246 Comments

@Jules,

Ha ha, I never get tired of a good debate :)


Mar 27, 2009 at 2:52 PM // reply »
25 Comments

Try using UUID's as order ID's, and you'll have some pissed customers. :)


Mar 27, 2009 at 3:03 PM // reply »
12 Comments

@Will Tomlinson,
Use incremental IDs for order IDs and folks know how many orders were placed, and try to snoop on other orders.

Sorta like project/invoice and check numbers. My good client can see month to month how many other invoices I've generated besides theirs. And I can see how many checks they've written in the same amount of time.

There would be no security issues in using incremental IDs so long as your app is written correctly. But still, it's kinda like dropping your drawers.

For orders/tracking I use links in emails with the UUID.


Mar 27, 2009 at 3:49 PM // reply »
25 Comments

That's why I use a UUID in another field in the orders table - not as the PK ID.

Then I use the UUID in combination with the PK ID, for any viewing, editing, deletions, etc.

Now, my customer has a nice, short order ID, and UUID that prevents tampering.


Mar 27, 2009 at 4:33 PM // reply »
12 Comments

I'm confused by your method. Doesn't the client still have the PKID, and use it to gain access to order information? They could then still tamper with it - no?


Mar 27, 2009 at 5:20 PM // reply »
25 Comments

The UUID is used much like an unlock key. You need the UUID in order to do anything with the record.

No one can tamper with it because it's nearly impossible to guess someone's UUID.


Mar 27, 2009 at 9:07 PM // reply »
12 Comments

Yes, thats why I like it so much. So why bother with an auto incrementing ID?


Mar 27, 2009 at 10:58 PM // reply »
25 Comments

The incrementing ID is just for the customer to use. Sometimes they call to inquire about an order. They can give my client the four digit ID instead of some long UUID.


Mar 28, 2009 at 11:12 AM // reply »
7 Comments

Backend processing and the CLIENT can use the Auto PKID to simplify look-ups and processing... Such as a means of using @@identity or last insert id on the backend (as already mentioned) or a quick order lookup for the CLIENT... not to be confused with the consumer.

Unless it is in an authenticated section of your application, or you have taken other measures to thwart enumeration, you would never display any order information based on an auto incrementing PKID without combining it with something that ensures the user should be able to see it. Such as a UUID

Securing order information is of course only one scenario. I typically use a secondary UUID field in tables that hold file information for which I don't want the download links easily enumerated. The UUID is passed through the URL as a download key. So a file download link might look like...

http://thedomain.com/files/#fileID#/#downloadKey#

-or-

http://thedomain.com/files/?fileid=#fileID#&downloadKey=#downloadKey#

The where clause on the file lookup would simply be...

where fileID = <cfqueryparam etc... value="#url.fileID#" />
AND downloadKey = <cfqueryparam etc... value="#url.downloadKey#" />

Without the combination of both unique columns, the file record cannot be recovered.


Mar 29, 2009 at 7:54 PM // reply »
110 Comments

Could just use stored procedures and pass parameters off to them. Set the result returned to be the id you're looking for. You wouldn't have to run multiple queries in your cf pages then.


Mar 30, 2009 at 9:19 AM // reply »
11,246 Comments

@Gareth,

I could do that, but then I'd have to write stored procedures :)


Mar 30, 2009 at 9:22 AM // reply »
110 Comments

Have your DBA do it...his name's Ben too, right? :)


Mar 30, 2009 at 9:27 AM // reply »
11,246 Comments

@Gareth,

Ha ha ha, yeah, but he's sooo lazy.


Mar 19, 2010 at 7:26 PM // reply »
1 Comments

Thank you very much for this post. Adding allowMultiQueries="true" in context.xml didn't help until I added it to url as allowMultiQueries=true

Good idea is to use prepared statements and it will help you to avoid possible SQL injection.


Feb 1, 2013 at 9:34 AM // reply »
1 Comments

what if you simple remove any semicolons that are passed in a variable before they reach the query. I can't think of a situation where a semi colon would be legitimately passed from a public form.

#REPLACE(variablename,";","","all")#',

would that be sufficient protection?



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools