-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Gerfried Günteer wrote:
Hi,
I'm running MySQL-Server 2.23.55-nt under Windows XP SP1 and use Connector/J 3.0.6 . Some fields in my database contain windows pathnames including backslashes, for example doc\testdat. When I try
PreparedStatement psZuBearb = conn[dbindex].prepareStatement("select dokid, pfadname, anzeigepfad from dokument where pfadname like ?"); psZuBearb.setString(1, "doc\\%"); ResultSet rs = psZubearb.excuteQuery();
my resultset is empty. If I try -pszuBearb.setString(1, "doc%");- everything is ok. In Jbuilder's Datapilot I can type
select dokid, pfadname, anzeigepfad from dokument where pfadname like 'doc\\\%'
and get the right results but that is not a correct syntax for a String in Java. This behaviour is the same in the version 2.0.x of Connector/J.
Please help.
Gerfried Günter
This is caused by the way the MySQL parser works, and how the 'LIKE' escape characters work. When you use 'doc\\\%' in a LIKE clause, it evaluates to 'doc%', which is probably not what you want:
"Note: Because MySQL uses the C escape syntax in strings (for example, `\n'), you must double any `\' that you use in your LIKE strings. For example, to search for `\n', specify it as `\\n'. To search for `\', specify it as `\\\\' (the backslashes are stripped once by the parser and another time when the pattern match is done, leaving a single backslash to be matched)."
(from http://www.mysql.com/doc/en/String_comparison_functions.html)
Given that the SQL parser also needs backslashes escaped, and you're using prepared statements (which will escape them for you), and that Java requires them to be escaped as well (whew, that's a _lot_ of escaping to remember), what you want to use is 'doc\\\\%'.
-Mark
- -- MySQL 2003 Users Conference -> http://www.mysql.com/events/uc2003/
For technical support contracts, visit https://order.mysql.com/?ref=mmma
__ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mark Matthews <[EMAIL PROTECTED]> / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java /_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA <___/ www.mysql.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.1.90 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+Z3GCtvXNTca6JD8RAtSDAKC/zjchAoSMpy1m5HOlILH1x/Wr7QCggm7y uH9//MD5nRfwpDZQW1CuPEs= =iuCc -----END PGP SIGNATURE-----
--------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php