Prepared Statements, Again!
Okay, earlier this year I figured out that the reason for our binary data problems when retrieving stored files from the database was the use of PreparedStatement. Well, we don’t use it for files, however we do still use it in so many other plaves in our code. We kept getting some recurring errors the most common one being that the placeholders had not been bound with objects before running the statment. Basically, PrepareCall() failed. We stepped through multiple times until we found an example where the error was found and found that in fact, there was no problem with the bound SQL generated by the PreparedStatement. So the error was being thrown for absolutely no reason that we could fathom. So, I did the exact same fix as for the binary data retrieval bugs and it fixed the problem. There seems to be major problems with the PreparedStatement calls and so now we just grab the sql that has been prepared, and then run it directly. For those who don’t remember how this was done, here is some sample code:
//Prepare the statement PreparedStatement statement = prepareStatement(query, variables, values); //Strip out the object information String statementString = statement.toString(); statementString = statementString.substring(statementString.indexOf('-')+1); //Original query execution //return statement.executeQuery(); return statement.executeQuery(statementString);
Just as some notes, prepareStatement() takes the query and binds all the values to the string. The next line gets the value of the PreparedStatement as a string. This will yield something similar to this:
com.mysql.jdbc.ServerPreparedStatement[3] - call impr_linkable_object_find_connected_by_type(2, ‘org.impresario.core’, ‘user’, ‘org.impresario.core’, ‘project’)
As you can see, there is information about the object before you get the sql. The following line strips everything before that first - so that you are left with only the sql call itself which is then executed independently as a string.
Suddenly, we no longer have that annoying problem popping up.
August 18th, 2009 at 3:24 am e
6OSjYz vrhgwrxidqtt, [url=http://mjuykhfowtpm.com/]mjuykhfowtpm[/url], [link=http://bjyfjcsoqjvr.com/]bjyfjcsoqjvr[/link], http://mptzmeyglmne.com/
August 19th, 2009 at 7:22 pm e
Cialis Soft Tabs, >:-[[[,
August 20th, 2009 at 4:46 am e
VPXL,
PP,
August 20th, 2009 at 4:47 am e
Female Viagra, lqunano,
August 20th, 2009 at 4:47 am e
Cialis Professional, 8],
August 20th, 2009 at 2:04 pm e
buy accutane, =DD,
August 20th, 2009 at 2:04 pm e
Cialis Soft Tabs, :]]],
August 20th, 2009 at 2:04 pm e
Levitra Super Active+, youcjiivlls,
August 20th, 2009 at 2:05 pm e
Viagra Super Active+, zrivn,
August 20th, 2009 at 2:05 pm e
Cialis Soft Tabs, >:-DD,
August 20th, 2009 at 2:05 pm e
buy accutane, apxxqju,
August 24th, 2009 at 3:26 am e
xanax tramadol, 4265,
August 24th, 2009 at 3:26 am e
get tramadol, qnkvrxv,
August 24th, 2009 at 3:26 am e
buy fioricet, pnd,
August 24th, 2009 at 3:27 am e
order viagra online, >:],
August 24th, 2009 at 3:27 am e
cheap viagra, >:]]],
August 24th, 2009 at 3:27 am e
buy viagra online, :[[[,
August 24th, 2009 at 3:27 am e
valtrex, 8P,
August 24th, 2009 at 11:54 am e
valtrex, bgfax,
August 24th, 2009 at 11:54 am e
sildenafil citrate, koih,
August 24th, 2009 at 11:54 am e
cheap cialis, 8-[[[,
August 24th, 2009 at 11:55 am e
tramadol, 969373196,
August 24th, 2009 at 7:27 pm e
buy viagra online, 6594570672,
August 24th, 2009 at 7:27 pm e
get tramadol, :-O,
August 24th, 2009 at 7:28 pm e
sildenafil citrate, =DD,
August 24th, 2009 at 7:28 pm e
cialis generic viagra, wskagysp,
August 24th, 2009 at 7:28 pm e
valtrex, 8-D,
August 25th, 2009 at 4:00 am e
get tramadol, =-)),