Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2003, 04:21 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default DATABASEMETADATA

i have a given database. i need to find out all the tables in it.and for each table, i need to find the attribute names and their type. can some1 help me with this.

for ex: if a user submits a query, the datatype of resulting query must be known to use getINT() etc and what are the attribute names(person_id) etc.


 
Old August 22nd, 2003, 06:15 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is what i am doing: but i need to know the each tables attribute name and their types(int etc). what this code does is simply print all the tables in the database .



Class.forName("com.mysql.jdbc.Driver").newInstance ();
                    Connection myCom = DriverManager.getConnection("jdbc:mysql://localhost/lab2_movies?user=nishant&password=wrox");
                    Statement stmt = myCom.createStatement();
                    DatabaseMetaData dbmd = null;
                    ResultSetMetaData rsmd = null;
                    ResultSet rst;

dbmd = myCom.getMetaData();
       rst = dbmd.getTables( "lab2_movies", "%", "%",null);
                     rsmd = rst.getMetaData();

                 for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
                     System.out.print( rsmd.getColumnName(i) + "\t" );
                         System.out.print( rsmd.getColumnLabel(i) + "\t" );
            }
                    System.out.print( "\n" );
                    System.out.println( "-------------------------------------------------------------------------------" );

                    while (rst.next()) {
                        for(int i = 1;i <= rsmd.getColumnCount(); i++ ) {
                         System.out.print( rst.getString(i) + "\t\t" );
                         System.out.print( "\n" );
                        }
                        }//while










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.