Problem using PostgreSQL 9.0.4 with Java

From: Arun Nadar <arun_rt(at)rocketmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Problem using PostgreSQL 9.0.4 with Java
Date: 2011-09-07 20:45:28
Message-ID: 1315428328.86698.YahooMailNeo@web137604.mail.in.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

I am currently using 'PostgreSQL
9.0.4' database with JDBC driver 'postgresql-9.0-801.jdbc4'. In my Java
program normal SELECT query didn't work.
ie, 

try {
            Class.forName("org.postgresql.Driver");
            connection = DriverManager.getConnection("jdbc:postgresql://localhost/Student","postgres","postgres");
            statement = connection.createStatement();
            String sql="SELECT Id, Name FROM Student ORDER BY Id";     // problem

            resultSet = statement.executeQuery(sql);
            if(resultSet.next()) {
                String id=resultSet.getString(1);
                String name=resultSet.getString(2);
            }   
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
   
            connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

I directly write a query via pgAdmin III the above SELECT query didn't work
{ SELECT Id, Name FROM Student ORDER BY Id; }

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.
 
Thanks & Regards
Arun.R.T

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-09-07 20:50:55 Re: conditional insert
Previous Message Andrew Sullivan 2011-09-07 20:04:54 Re: conditional insert