One. Java methods
Get all the table names under the current database
Java code
- Public void Gettablenamebycon (Connection con) {
- try {
- DatabaseMetaData meta = con.getmetadata ();
- ResultSet rs = meta.gettables (null, null, null,
- New string[] { "TABLE"});
- While (Rs.next ()) {
- SYSTEM.OUT.PRINTLN ("table name:" + rs.getstring (3));
- SYSTEM.OUT.PRINTLN ("table-owned User name:" + rs.getstring (2));
- System.out.println ("------------------------------");
- }
- Con.close ();
- } catch (Exception e) {
- try {
- Con.close ();
- } catch (SQLException E1) {
- //TODO auto-generated catch block
- E1.printstacktrace ();
- }
- //TODO auto-generated catch block
- E.printstacktrace ();
- }
- }
Two. Get all the table names in the database using SQL statements
--mysql Database
Java code
- Show tables;
--oracle Database (table under the currently logged on user)
Java code
- Select Uo.object_name from user_objects uo where uo.object_type = ' TABLE ';
--sql Server 2000/2005 Database
Java code
- Select name from sysobjects
--sybase Database
Java code
- Select name from sysobjects where type=' U ';
--DB2 Database
Java code
- Select TabName from syscat.tables where Tabschema = current schema; //
Get all user tables below the current mode
Transferred from: http://hi.baidu.com/rybwxn/blog/item/1a59502a75a7de25d52af1cc.html
Java gets the name of the table in the database