db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George H <george....@gmail.com>
Subject Re: Escaping special characters
Date Mon, 23 Feb 2009 15:05:17 GMT
I am in a situation where I need to construct sql statements (many
different types of INSERT) and execute them in 1 batch.
Either way, I did find my problem, which lay somewhere else.

Though I did notice that derby only needs you to exclusively escape
single quotes.. while everything else is ok, unlike MySQL you need to
escape single quotes, carriage return, line feed, null (\0) and \Z
(\032)
--
George H
george.dma@gmail.com



On Mon, Feb 23, 2009 at 2:34 PM, Rick Hillegas <Richard.Hillegas@sun.com> wrote:
> George H wrote:
>>
>> Hi I'm a bit new to derby and I got stuck with escaping special
>> characters like \n and \r.
>> I'm constructing SQL insert statements in my java program and placing
>> text inside which contain EOLs. They are not being escaped or
>> something.
>> I'm familiar with MySQL in that it converts all \n to \\n, this does
>> not seem to work with derby, what does?
>> --
>> George H
>> george.dma@gmail.com
>>
>
> Hi George,
>
> Can you phrase your INSERT in terms of a JDBC '?' parameter? E.g.,
>
>  PreparedStatement ps = connection.prepareStatement( "INSERT INTO fooTable(
> stringColumn ) values ( ? )" )
>
> If so, then you just have to set the ? parameter equal to some Java string.
> All you need is the String escaping you use in other Java programs:
>
>  ps.setString( 1, "My string which contains\nsome newlines\n" );
>
> Hope this helps,
> -Rick
>

Mime
View raw message