Wednesday, February 17, 2010

using DatabaseMetaData

Java provides two classes "DatabaseMetaData" and "ResultSetMetaData" which helps a lot while retrieving data about tables in SQL.
So how to use these classes?

First establish connection with database

Connection con=DriverManager.getConnection(url,user,password);

After establishing connection with database we can retrieve data about database

DatabaseMetaData dbmd=con.getMetaData();

After this to get the table list from database we can use following method

String types[]={
ResultSet rs=dbmd.getTables(con.getCatalog(),null,null,types);
 Vector v=new Vector();

No comments:

Post a Comment

Ads Inside Post