I create a global temporary table in Oracle 11g using the following SQL statement.
SQL> CREATE GLOBAL TEMPORARY TABLE TEST (id int primary key);
Now How can I filter out this table using Connection.getMetaData().getTables
.Here I get the TABLE_TYPE = TABLE
instead of GLOBAL TEMPORARY
for above TEST
table
Following is my java code.
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class GetGlobalTempTables {
public static void main(String[] args) {
Connection connection = null;
Statement connStmt = null;
ResultSet res = null;
String dbURL = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "testuser";
String pass = "testpass";
try {
connection = DriverManager.getConnection(dbURL, user, pass);
DatabaseMetaData meta = connection.getMetaData();
res = meta.getTables(null, "TEST_SCHEMA", null, new String[] { "TABLE", "VIEW" });
while (res.next()) {
System.out.println(res.getString("TABLE_SCHEM") + ", " + res.getString("TABLE_NAME") + ", "
+ res.getString("TABLE_TYPE"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (res != null) {
res.close();
}
if (connStmt != null) {
connStmt.close();
}
if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}
Any help will be great appreciated...!