mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
JdbcUtils.showTables support postgresql.
This commit is contained in:
@@ -793,6 +793,9 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return OracleUtils.showTables(conn);
|
||||
}
|
||||
|
||||
if (JdbcConstants.POSTGRESQL.equals(dbType)) {
|
||||
return PGUtils.showTables(conn);
|
||||
}
|
||||
throw new SQLException("show tables dbType not support for " + dbType);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
package com.alibaba.druid.util;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.XAConnection;
|
||||
|
||||
@@ -28,4 +32,24 @@ public class PGUtils {
|
||||
public static XAConnection createXAConnection(Connection physicalConn) throws SQLException {
|
||||
return new PGXAConnection((BaseConnection) physicalConn);
|
||||
}
|
||||
|
||||
public static List<String> showTables(Connection conn) throws SQLException {
|
||||
List<String> tables = new ArrayList<String>();
|
||||
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery("SELECT tablename FROM pg_catalog.pg_tables where schemaname not in ('pg_catalog', 'information_schema', 'sys')");
|
||||
while (rs.next()) {
|
||||
String tableName = rs.getString(1);
|
||||
tables.add(tableName);
|
||||
}
|
||||
} finally {
|
||||
JdbcUtils.close(rs);
|
||||
JdbcUtils.close(stmt);
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user