Re: Problem in getting column names from DatabaseMetadata Object

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: stallapp <sree(dot)tallapalli(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problem in getting column names from DatabaseMetadata Object
Date: 2015-11-03 13:54:51
Message-ID: CADK3HH+QX6di4izH4=jKLSct_+n2NzNhEsdCpqm7Gc=h0HD7=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Leave the schema pattern null as well and it should work

Dave Cramer

davec(at)postgresintl(dot)com
www.postgresintl.com

On 3 November 2015 at 08:23, stallapp <sree(dot)tallapalli(at)gmail(dot)com> wrote:

> Hi,
>
> I am using the following code to get the column names of my postgres table
> but it fails. My database name is "employee" and table name is "employee".
>
> Postgres version : 9.3
> jdbc driver version : 9.3
>
> public class DBTest {
> public static void main(String[] args) throws Throwable {
> Connection conn = getDBConnection();
> DatabaseMetaData metaData = conn.getMetaData();
> ResultSet resultSet = metaData.getColumns(null,
> "employee", "employee",
> null);
>
> if (!resultSet.next())
> System.out.println("No result set Entries!!");
>
> while (resultSet.next()) {
>
> System.out.println(resultSet.getString("COLUMN_NAME"));
> }
> conn.close();
> }
>
> public static Connection getDBConnection() {
> Connection conn = null;
> try {
> Class.forName("org.postgresql.Driver");
>
> conn =
> DriverManager.getConnection("jdbc:postgresql://sampel.db:5432/data_gen",
> "postgres",
> "postgres");
> } catch (Throwable th) {
> th.printStackTrace();
> }
> return conn;
> }
>
> any ideas??
>
> Thanks
>
>
>
> --
> View this message in context:
> http://postgresql.nabble.com/Problem-in-getting-column-names-from-DatabaseMetadata-Object-tp5872498.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2015-11-03 13:55:21 version 1205
Previous Message Thomas Kellerer 2015-11-03 13:51:49 Re: Problem in getting column names from DatabaseMetadata Object