Escape sequences in JDBC Statements
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alex_Hall
Posted On:   Monday, August 19, 2002 03:55 PM

I am having problems with SQL INSERT type statements where consecutive escape characters are required, eg: for the source string "\'" I would expect the following code to work: "INSERT INTO ... VALUES('\\'')" Indeed, the above syntax works as expected in my DBMS's command line (I'm using MySQL with a JDBC driver). I consulted the Java documentation and hoped that specifying an alternative escape character might work, using the command {escape '[char]'} at the end of the SQL statement. However, I am still getting SQLException when I attempt to insert values containing consecutive escape characters. Is this standard JDBC behavior, or should I try to install a different JDBC driver?    More>>

I am having problems with SQL INSERT type statements where consecutive escape characters are required, eg: for the source string "\'" I would expect the following code to work:


"INSERT INTO ... VALUES('\\'')"


Indeed, the above syntax works as expected in my DBMS's command line (I'm using MySQL with a JDBC driver).


I consulted the Java documentation and hoped that specifying an alternative escape character might work, using the command {escape '[char]'} at the end of the SQL statement. However, I am still getting SQLException when I attempt to insert values containing consecutive escape characters. Is this standard JDBC behavior, or should I try to install a different JDBC driver?


Many thanks to anyone who tries to answer this, as I'm completely stuck!


Alex    <<Less

PROBLEM SOLVED

Posted By:   Alex_Hall  
Posted On:   Tuesday, August 20, 2002 04:53 AM

I've sorted out the problem, which I had mis-diagnosed in my initial message.


The driver was confused by escape sequences in substrings, ie:

INSERT INTO ... VALUES ( '..."...[escape sequence]..."...')


Ordinarily, escapes are not needed for double quotes within single quoted values, but the substitution of " with " solved the recognition problem.


For the record - there is nothing dodgy about the MySQL JDBC driver!


Alex

Re: Escape sequences in JDBC Statements

Posted By:   Anonymous  
Posted On:   Monday, August 19, 2002 04:01 PM

You might be knowing this

Why can't you try appending strings/characters to a StringBuffer and finally get the string and execute the sql, instead of hard coding everything inside a single string.
About | Sitemap | Contact