JDBC知识集锦
通过JDBC得到数据字典、数据库元数据信息
下面的例子中,获取到所有表的名称,并进行了截断。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
StringBuffer buff = new StringBuffer(); conn = getConnection(); conn.setAutoCommit( false ); String TABLE_NAME = "TABLE_NAME"; String[] TABLE_TYPES = { "TABLE" }; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables( null, null, null, TABLE_TYPES ); while ( tables.next() ) { String tabName = tables.getString( TABLE_NAME ); buff.append( "TRUNCATE TABLE " + tabName + ";" ); } conn.createStatement().execute( buff.toString() ); conn.commit(); |
如何使用HSQLDB内存模式
1 2 3 |
Class.forName( "org.hsqldb.jdbcDriver" ); Connection conn = DriverManager.getConnection( "jdbc:hsqldb:mem:test", "sa", "" ); conn.createStatement().execute( "SHUTDOWN" ); |
如何使用HSQLDB进程内(In-Process)模式
和内存模式类似,URL为:jdbc:hsqldb:file:/C:/testdb/testDbName
Leave a Reply