db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <Richard.Hille...@Sun.COM>
Subject Re: Escaping special characters
Date Mon, 23 Feb 2009 14:34:19 GMT
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,

View raw message