JdbcUtils.showTables support postgresql.

This commit is contained in:
wenshao
2017-08-10 15:27:58 +08:00
parent 52bb3da616
commit e693b08304
2 changed files with 27 additions and 0 deletions
@@ -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;
}
}