By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

Show table list of a database in java

P: 1
Hi, i have to print in java a list of all tables in a selected database. Here some code:
Expand|Select|Wrap|Line Numbers
  1. public String elegirtabla() throws SQLException{
  2.         cg.scanner();
  3.         System.out.println("Listado de base de datos del servidor "+cg.server+":");
  4.         rs= cg.con.getMetaData().getCatalogs();
  5.         while(rs.next()){
  6.            System.out.println(rs.getString("TABLE_CAT"));
  7.         }
  8.         System.out.println("Introduce la base a la que conectarte:");
  9.         cg.bd= cg.sc.next();
  10.         cg.con.setCatalog(cg.bd);
  11.         System.out.println("Listado de tablas en la base de datos "+cg.bd+":");
  12.         int avt=1;
  13.         rs= cg.con.getMetaData().getSchemas();
  14.         while(rs.next()){
  15.             System.out.println(rs.getString(avt));
  16.             avt++;
  17.         } //that's the code wrong i think, what do i have to write?
  18.         System.out.println("Introduce el nombre de la tabla");
  19.         tabla= cg.sc.next();
  20.         return tabla;
  21.     }
Jun 24 '12 #1
Share this Question
Share on Google+
2 Replies


100+
P: 126

Expert 100+
P: 1,043
I wonder why this question was moved.
The answer from PreethiGowri was pretty,
and was goog enough for /me to give the results.
It even was more complete than the question asked....

But (sorry) i was not asking the question ;)
Nov 13 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.