pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Newlines in String inserts with JDBC
4+ messages / 3 participants
[nested] [flat]

* Newlines in String inserts with JDBC
@ 2000-09-28 00:18  Ken Kachnowich <khkachn@toad.net>
  0 siblings, 2 replies; 4+ messages in thread

From: Ken Kachnowich @ 2000-09-28 00:18 UTC (permalink / raw)
  To: pgsql-interfaces

Is there a method that could be used to insert Strings containing
newline charaters using the JDBC interface? I could replace them
with some character before the insert but what would be a good 
character to use?

Thanks,

Ken



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* RE: Newlines in String inserts with JDBC
@ 2000-09-28 00:33  Friedman, Eric <eric@eTranslate.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Friedman, Eric @ 2000-09-28 00:33 UTC (permalink / raw)
  To: 'khkachn@NOSPAMtoad.net' <khkachn@NOSPAMtoad.net>; pgsql-interfaces

Why do you need to replace them?

-----Original Message-----
From: Ken Kachnowich [mailto:khkachn@toad.net]
Sent: Wednesday, September 27, 2000 5:18 PM
To: Postgres interfaces
Subject: [INTERFACES] Newlines in String inserts with JDBC


Is there a method that could be used to insert Strings containing
newline charaters using the JDBC interface? I could replace them
with some character before the insert but what would be a good 
character to use?

Thanks,

Ken



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Newlines in String inserts with JDBC
@ 2000-09-28 09:21  Jens Carlberg <jenca@lysator.liu.se>
  parent: Ken Kachnowich <khkachn@toad.net>
  1 sibling, 0 replies; 4+ messages in thread

From: Jens Carlberg @ 2000-09-28 09:21 UTC (permalink / raw)
  To: pgsql-interfaces

Ken Kachnowich wrote:
> 
> Is there a method that could be used to insert Strings containing
> newline charaters using the JDBC interface?

I haven't tried this, but allow me to speculate:

1. If new-line isn't allowed as a char, it can't be done at all. Then
you have to invent a mapping on your own. I would recommend "\n"; it's
failrly standard. Note that this means you have to escape "\" too; I
recommend "\\".

2. However, if new-line is allowed (and I suspect it is), it should
probably be 'escaped' somehow. This might be database specific; your
Java-code shouldn't be, though. To solve this, use the PreparedStatement
class, and simply set the String:

String aString = "Row 1: Before newline\nRow 2: After newline";
PreparedStatement aStmt = aConn.prepareStatement();
aStmt.setString(aString);

This way, you delegate to the classes developed for this specific
database to handle all issues specific to the database, as it should be.

> Ken
///Jens Carlberg




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Newlines in String inserts with JDBC
@ 2000-09-28 22:07  Ken Kachnowich <khkachn@toad.net>
  parent: Ken Kachnowich <khkachn@toad.net>
  1 sibling, 0 replies; 4+ messages in thread

From: Ken Kachnowich @ 2000-09-28 22:07 UTC (permalink / raw)
  To: pgsql-interfaces

Sorry, I did not give enough information.
I am using the Serialize class. It builds an SQL insert statement in 
a String and the back end seems to fail if there is a newline in 
a text fields value.
If the PreparedStatement and setString work with newlines then I can
look into using that. I need to get a resultSet back, though, so I can
figure out what the record OID is of the record I just inserted.

Ken

Ken Kachnowich wrote:
> 
> Is there a method that could be used to insert Strings containing
> newline charaters using the JDBC interface? I could replace them
> with some character before the insert but what would be a good
> character to use?
> 
> Thanks,
> 
> Ken



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2000-09-28 22:07 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-09-28 00:18 Newlines in String inserts with JDBC Ken Kachnowich <khkachn@toad.net>
2000-09-28 09:21 ` Jens Carlberg <jenca@lysator.liu.se>
2000-09-28 22:07 ` Ken Kachnowich <khkachn@toad.net>
2000-09-28 00:33 RE: Newlines in String inserts with JDBC Friedman, Eric <eric@eTranslate.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox