Show table list of a database in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drkwzrd
    New Member
    • Jun 2012
    • 1

    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:
    Code:
    public String elegirtabla() throws SQLException{
            cg.scanner();
            System.out.println("Listado de base de datos del servidor "+cg.server+":");
            rs= cg.con.getMetaData().getCatalogs();
            while(rs.next()){
               System.out.println(rs.getString("TABLE_CAT"));
            }
            System.out.println("Introduce la base a la que conectarte:");
            cg.bd= cg.sc.next();
            cg.con.setCatalog(cg.bd);
            System.out.println("Listado de tablas en la base de datos "+cg.bd+":");
            [B]int avt=1;[/B]
            [B]rs= cg.con.getMetaData().getSchemas();[/B]
            [B]while(rs.next()){[/B]
                [B]System.out.println(rs.getString(avt));[/B]
                [B]avt++;[/B]
            [B]}[/B] [U]//that's the code wrong i think, what do i have to write?[/U]
            System.out.println("Introduce el nombre de la tabla");
            tabla= cg.sc.next();
            return tabla;
        }
    Last edited by drkwzrd; Jun 24 '12, 03:12 AM. Reason: bad writed
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    #2
    This might help you:)

    In database system it is very important to know about the tables. To work with this, it is very important to know how to retrieve a table and create a table in the database.

    Comment

    • Luuk
      Recognized Expert Top Contributor
      • Mar 2012
      • 1043

      #3
      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 ;)

      Comment

      Working...