derby - Java DB Database, check for all table names -
i've got embedded derby database
in java application, , have multiple table's
(that created , deleted, nothing set in stone). wanted able return list of names of tables
in database
have display list in application information them.
easiest way so? don't need code method or methods. i'm terrible google-fu user.
currently code works grabbing resultset
specific table name entered, it's testing purposes , need able display full list of tables have.
edit: current workaround different posted. have table
holds table names created , updates when 1 created/deleted. not best approach works me right now.
databasemetadata metadata = connection.getmetadata(); resultset resultset = metadata.gettables(null, "schenaname", "%" ,new string[] {"table"} ); while (resultset.next()) { system.out.println(resultset.getstring(3)); }
adding new answer:
connection connection = getdbconnection(); databasemetadata dbmetadata = connection.getmetadata(); //getting catalogs mysql db, if not working db, try dbmetadata.getschemas(); resultset catalogs = dbmetadata.getcatalogs(); while(catalogs.next()){ string catalogname = catalogs.getstring(1); //excluding table names "mysql" schema mysql db. if(!"mysql".equalsignorecase(catalogname)){ resultset tables = dbmetadata.gettables(catalogname, null, null, null); while(tables.next()){ system.out.println(catalogname + "::"+tables.getstring(3)); } } }
Comments
Post a Comment