473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Show table list of a database in java

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
2 2743
Luuk
1,047 Expert 1GB
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

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

Similar topics

0
by: Dan Muey | last post by:
Howdy List! A couple questions about finding the disk space used by a = table/database: 1) First how can I get the size a table is taking up on disk? Is it the 'Data_length' field in: SHOW...
0
by: Jerry | last post by:
The "SHOW TABLE STATUS" command seems to return a result set, just like "SELECT * FROM SomeTable". Therefore, since the following is valid: SELECT * FROM (SELECT * FROM SomeTable) I...
3
by: vboilay | last post by:
Hi, Is there a way to get VIA SQL the table list for a specified database ? Same thing for the database list ... and.... column list Something that could look like scanning the syabse sysobject...
0
by: 400PM | last post by:
Hi, I am using java to retrieve a resultset with "show table status" mysql command. I am having problem reading the and column. In the metadata object it is showing as VARCHAR but when I do...
0
by: Deepak Rao G | last post by:
Hi All , I have a UDB 8.1 to look after, when i check on the DB partition groups, it shows me only 2 groups ( as shown below) & misses IBMTEMPGROUP !! I checked the IBM official...
1
by: aa | last post by:
How to show the list of the pictures from MS access in the html page, for instance in the table or datagrid VB thanks
1
by: runway27 | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
2
by: Sudhakar | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
0
by: runway27 | last post by:
hi my question is about "SHOW TABLE STATUS LIKE 'tablename'"; following is the code i am presently using ================================================================== $conn =...
1
by: anna george | last post by:
hi! i have created a class 'ChangePassword' which is called from 'login' both extending jframe. i'm trying to take a new password from the user and update the savelogin table in database Employ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.