You can query the meta data of a database to obtain the data table.
Public static Boolean doestableexist (string tablename) {<br/> connection con = NULL; <br/> hashset <string> set = new hashset <string> (); <br/> try {<br/> class. forname (databaseconnection. getdatabaseconnection (); <br/> con = drivermanager. getconnection (databasename. con); <br/> databasemetadata meta = con. getmetadata (); <br/> resultset res = meta. gettables (null, <br/> New String [] {"table"}); <br/> while (res. next () {<br/> set. add (res. getstring ("table_name"); <br/>}< br/> res. close (); <br/> con. close (); <br/>}catch (exception e) {<br/> system. err. println ("exception:" + E. getmessage (); <br/>}< br/> // system. out. println (SET); <br/> return set. contains (tablename. touppercase (); <br/>}
ReplaceDatabaseconnection. getdatabaseconnection ()
AndDatabasename. Con
You just need to connect to the database. Refer to another article on how to connect a local database: http://blog.csdn.net/autofei/archive/2010/05/24/5621274.aspx
Another method is to connect to the database and capture exceptions.
// Connection = new databaseconnection (databaseconnection. derby, "", "DB", "UNCC", "UNCC"); <br/> connection = new databaseconnection (databaseconnection. s, "localhost", "Postgres", <br/> "Postgres", "Postgres"); <br/> database = new database (connection ); </P> <p> // checks to see if database structure already exists <br/> Boolean exists = true; <br/> statement stmt = connection. getstatement (); <br/> try {<br/> stmt.exe cutequery ("select * From qgram"); <br/>} catch (exception E) {<br/> connection. rollback (); <br/> exists = false; <br/>}
Reference: http://www.herongyang.com/jdbc/JDBC-ODBC-Flat-File-List-Tables.html