views:

31

answers:

1

Hi,

I am connecting to a 4D (fourth dimension brand) database with its crappy jdbc driver.

I have a CLOB on the database and when I fetch it either through getString or getClob, I don't get line returns, everything seems to come in one line.

But, if I do do a select on NetBeans database explorer and I copy and paste the value on the editor, It DOES pickup up the \n.

I have noticed that instead of \n\ I am getting character 13

Anybody know why these \n line returns are not coming as they should?

I am using windows 7 64 bit

Pablo

A: 

In Windows, the line terminator is \r, under Linux it's \n. Whenever files are exchanged between different systems, great confusion arises.

If you're seeing the wrong kind of line terminator, you'll want to convert those strings. Problem solved.

Carl Smotricz
Thanks Carl,but how does netbeans pick this up and I don't? wouldnt be easier to set some encoding parameter on the jdbc connection and forget conversion of every single string?
Pablo
There's a tradition in the Open Source programming community to "accept many formats, produce few" (or something like that). It's very simple to treat either CR or LF as a line terminator, and then it doesn't matter which one is coming in, it makes your program more flexible.
Carl Smotricz
As for the conversion switch: I wouldn't be surprised if it was available in some DBs. But I don't think it's a good idea. If you are able to ask the DB to check and convert data back and forth for you on every access, you create a lot more useless overhead than if you, in your application(s), consistently sanitize your data before writing it to the DB. Once you're aware of the potential problem, it's not difficult at all to fix.
Carl Smotricz
Reading your question again, it looks like your data was written on a Unix system, and probably as you intended, with \n. Could it be that your JDBC driver is indeed converting to \r for you, thinking it's doing you a favor?
Carl Smotricz
I went digging on the NetBeans code to find out why NetBeans fetches and displays data correctly and I don't. I couldn't find anything in NB code that wasn't like mine.... Yes, I know i can just convert them, I was just curious... Thanks anyways Carl, hey by the way I see you have a bit swing experience... Do you know a decent textfield autocomplete component for swing with drop down (like the one google main page)Pablo
Pablo
@Pablo: See my previous comment: It's possible you just need to *stop* your JDBC driver from doing the unwanted conversion, rather than you doing it. I have no way of knowing for sure, though. As for the text field component, no, I write pretty boring apps with standard components from the JDK only ;)
Carl Smotricz
I used to as well, but this jdesktop.swingx is similar but just a bit nicer...
Pablo