Re: Inserting a backslash

From: Chris (chris2k01_at_hotmail.com)
Date: 07/21/04


Date: Wed, 21 Jul 2004 21:34:02 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joe Ray wrote:

> I am trying to insert string data into my MySQL database. Some of
> the string data has a backslash as a character. I tried to make a
> simple insert of a backslash into the database using the following
> statement in java. Notice that i used two backslashes.
>
> stmt.executeUpdate("INSERT INTO DICTIONARY VALUES('\\')");
>
> However the database did not accept that I received an SQL
> exception. I am stumped. Any suggestions? Thanx in advance
>
> Joe

Hi,
You want four backslashes, not two. Here's why:

You type: \\\\

1. Java uses \ as an escape character. You need \\ to write a \ in the
actual class file when it's compiled.

MySQL sees: \\

2. MySQL uses \ as an escape character. You need \\ for MySQL to
interpret it as \. Otherwise, you're escaping the quote, which is
definitely not what you want.

Into the database goes: \

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA/uF0nwjA8LryK2IRAgVYAKDuSW9Z5Pwjhu4MxCmivhFSyFlTLQCg8wsx
8Fx6m4aCaV3tByzeaQSQYrQ=
=7wrn
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: Unrecognized escape sequences in string literals
    ... character without knowing the context, ... '\n' maps to the string chr. ... In both cases the backslash in the literal have the same meaning: ... escape every backslash, ...
    (comp.lang.python)
  • Re: New Line Constant Error!
    ... > make a special character that you can't type into your program. ... > tries to combine the backslash with the following character to create ... which the compiler reads as a special sequence that folds down into ... because the sequence backslash-en is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Eigenartiges Verhalten von "String[] java.lang.String.split(String regex)" - Falscher Split
    ... "It is an error to use a backslash prior to any alphabetic character ... Alle anderen Backslashes sind nicht erlaubt und ... musst du das mit ...
    (de.comp.lang.java)
  • Re: gfortran diagnostics and so on
    ... Well, in f0003, backslash is part of the standard Fortran character set. ... Because the backslash is part of the standard Fortran character set, the default behavior should be the printable character, **NOT** some kind of magic introductory character that transforms the interpretation of following character. ... The one I like best is to use one of the popular extensions to designate a particular literal string according to the C language. ...
    (comp.lang.fortran)
  • Re: New Line Constant Error!
    ... it is an "escape" that combines with the character after it to ... So, any time you type a string and put a backslash \ in it, the ... which the compiler reads as a special sequence that folds down into ... special-character processing on this one. ...
    (microsoft.public.dotnet.languages.csharp)