Java provides two classes "DatabaseMetaData" and "ResultSetMetaData" which helps a lot while retrieving data about tables in SQL.
After this to get the table list from database we can use following method
So how to use these classes?
First establish connection with database
Class.forName(driver); 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[]={ "TABLE" }; ResultSet rs=dbmd.getTables(con.getCatalog(),null,null,types); while(rs.next()) { Vectorv=new Vector (); System.out.println(rs.getString("TABLE_NAME")); }
Comments
Post a Comment