Re: Problem using PostgreSQL 9.0.4 with Java - Mailing list pgsql-general

From David Johnston
Subject Re: Problem using PostgreSQL 9.0.4 with Java
Date
Msg-id 00e201cc6da9$dfc1ea70$9f45bf50$@yahoo.com
Whole thread Raw
In response to Problem using PostgreSQL 9.0.4 with Java  (Arun Nadar <arun_rt@rocketmail.com>)
List pgsql-general

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Arun Nadar
Sent: Wednesday, September 07, 2011 4:45 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Problem using PostgreSQL 9.0.4 with Java

 

Hi

 

but it work by putting " ",  like this SELECT "Id", "Name" FROM "Student" ORDER BY "Id";

 

in java String,  inside of double inverted commas another is does not possible.

 

how this code is implement through java program. please kindly send me the solution for this.

 

 

To include the “quote” symbol in a Java string you need to escape it with the “back-slash” symbol (i.e.,  “\” ) as so:

 

String var = “SELECT \”Id\” FROM \”Table\””;

 

The reason you are having to do this is you defined your table and column names in a case-sensitive manner BUT PostgreSQL automatically converts to lowercase any identifier that is not enclosed in quotes.

 

I would suggest you do some more reading on how Strings in Java work since if you missed how to include the common quote in a String literal you likely missed some other important rules/behavior as well.

 

On the PostgreSQL side I do not know how you created your table(s) but unless you have some overriding reason to avoid doing so you should stick to lower-case; it will make using those tables from within Java much easier (during your hard-coded queries phase of development).  You can still use mixed-case in Java (without the quotes) and then let PostgreSQL convert it into lower-case for you.

 

David J.

 

 

 

 

 

pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: Re: Demoting master to slave without an rsync...is it safe?
Next
From: Joy Smith
Date:
Subject: pivoting data?