Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.


  #2 (permalink)  
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


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 03:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.