pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem in getting column names from DatabaseMetadata Object
4+ messages / 3 participants
[nested] [flat]
* Problem in getting column names from DatabaseMetadata Object
@ 2015-11-03 13:23 stallapp <sree.tallapalli@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: stallapp @ 2015-11-03 13:23 UTC (permalink / raw)
To: pgsql-jdbc
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....
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem in getting column names from DatabaseMetadata Object
@ 2015-11-03 13:51 Thomas Kellerer <spam_eater@gmx.net>
parent: stallapp <sree.tallapalli@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Kellerer @ 2015-11-03 13:51 UTC (permalink / raw)
To: pgsql-jdbc
> 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".
But you are connecting to a database called "data_gen":
> DriverManager.getConnection("jdbc:postgresql://sampel.db:5432/data_gen", "postgres"
Also: what exactly does "it fails" mean? Do you get an exception? If yes, what is the exception?
Thomas
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem in getting column names from DatabaseMetadata Object
@ 2015-11-03 13:54 Dave Cramer <pg@fastcrypt.com>
parent: stallapp <sree.tallapalli@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Dave Cramer @ 2015-11-03 13:54 UTC (permalink / raw)
To: stallapp <sree.tallapalli@gmail.com>; +Cc: pgsql-jdbc
Leave the schema pattern null as well and it should work
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On 3 November 2015 at 08:23, stallapp <sree.tallapalli@gmail.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....
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem in getting column names from DatabaseMetadata Object
@ 2015-11-03 15:34 stallapp <sree.tallapalli@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 4+ messages in thread
From: stallapp @ 2015-11-03 15:34 UTC (permalink / raw)
To: pgsql-jdbc
Works with following change.
ResultSet resultSet = metaData.getColumns(null, null, "employee", null);
Thanks
--
View this message in context: http://postgresql.nabble.com/Problem-in-getting-column-names-from-DatabaseMetadata-Object-tp5872498p...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2015-11-03 15:34 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03 13:23 Problem in getting column names from DatabaseMetadata Object stallapp <sree.tallapalli@gmail.com>
2015-11-03 13:51 ` Thomas Kellerer <spam_eater@gmx.net>
2015-11-03 13:54 ` Dave Cramer <pg@fastcrypt.com>
2015-11-03 15:34 ` stallapp <sree.tallapalli@gmail.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