Package com.alibaba.druid.util
Class JdbcUtils
- java.lang.Object
-
- com.alibaba.druid.util.JdbcUtils
-
- All Implemented Interfaces:
JdbcConstants
public final class JdbcUtils extends Object implements JdbcConstants
- Author:
- wenshao [szujobs@hotmail.com]
-
-
Field Summary
-
Fields inherited from interface com.alibaba.druid.util.JdbcConstants
ALI_ORACLE, ALI_ORACLE_DRIVER, ALIYUN_ADS, ALIYUN_DRDS, CLICKHOUSE, CLICKHOUSE_DRIVER, CLICKHOUSE_DRIVER_NEW, DB2, DB2_DRIVER, DB2_DRIVER2, DB2_DRIVER3, DERBY, DM, DM_DRIVER, ELASTIC_SEARCH, ELASTIC_SEARCH_DRIVER, ENTERPRISEDB, ENTERPRISEDB_DRIVER, GBASE, GBASE_DRIVER, GBASE8S_DRIVER, GOLDENDB_DRIVER, GREENPLUM, GREENPLUM_DRIVER, H2, H2_DRIVER, HBASE, HIVE, HIVE_DRIVER, HSQL, INFORMIX, JTDS, KDB, KDB_DRIVER, KINGBASE, KINGBASE_DRIVER, KINGBASE8_DRIVER, KYLIN, KYLIN_DRIVER, LEALONE, LEALONE_DRIVER, LOG4JDBC, LOG4JDBC_DRIVER, MARIADB, MARIADB_DRIVER, MOCK, MYSQL, MYSQL_DRIVER, MYSQL_DRIVER_6, MYSQL_DRIVER_603, MYSQL_DRIVER_REPLICATE, OCEANBASE, OCEANBASE_DRIVER, OCEANBASE_DRIVER2, OCEANBASE_ORACLE, ODPS, ODPS_DRIVER, OPENGAUSS_DRIVER, ORACLE, ORACLE_DRIVER, ORACLE_DRIVER2, OSCAR, OSCAR_DRIVER, PHOENIX, PHOENIX_DRIVER, POLARDB, POLARDB_DRIVER, POLARDB2, POLARDB2_DRIVER, POLARDBX_DRIVER, POSTGRESQL, POSTGRESQL_DRIVER, PRESTO, PRESTO_DRIVER, SQL_SERVER, SQL_SERVER_DRIVER, SQL_SERVER_DRIVER_JTDS, SQL_SERVER_DRIVER_SQLJDBC4, SQLITE, SQLITE_DRIVER, SUNDB, SUNDB_DRIVER, SYBASE, TAOS_DATA, TAOS_DATA_RS, TERADATA, TERADATA_DRIVER, TIDB, TIDB_DRIVER, TRINO, TRINO_DRIVER, TYDB, TYDB_DRIVER, XUGU, XUGU_DRIVER
-
-
Constructor Summary
Constructors Constructor Description JdbcUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(Closeable x)static voidclose(Blob x)static voidclose(Clob x)static voidclose(Connection x)static voidclose(ResultSet x)static voidclose(Statement x)static DrivercreateDriver(ClassLoader classLoader, String driverClassName)static DrivercreateDriver(String driverClassName)static voidexecute(Connection conn, String sql)static voidexecute(Connection conn, String sql, List<Object> parameters)static voidexecute(DataSource dataSource, String sql, Object... parameters)static voidexecute(DataSource dataSource, String sql, List<Object> parameters)static List<Map<String,Object>>executeQuery(Connection conn, String sql, List<Object> parameters)static <T> voidexecuteQuery(DataSource dataSource, ResultSetConsumer<T> consumer, String sql, Object... parameters)static List<Map<String,Object>>executeQuery(DataSource dataSource, String sql, Object... parameters)static List<Map<String,Object>>executeQuery(DataSource dataSource, String sql, List<Object> parameters)static intexecuteUpdate(Connection conn, String sql, List<Object> parameters)static intexecuteUpdate(DataSource dataSource, String sql, Object... parameters)static intexecuteUpdate(DataSource dataSource, String sql, List<Object> parameters)static StringgetCreateTableScript(Connection conn, DbType dbType)static StringgetCreateTableScript(Connection conn, DbType dbType, boolean sorted, boolean simplify)static StringgetDbType(String rawUrl, String driverClassName)static DbTypegetDbTypeRaw(String rawUrl, String driverClassName)static StringgetDriverClassName(String rawUrl)static StringgetTypeName(int sqlType)static voidinsertToTable(Connection conn, String tableName, Map<String,Object> data)static voidinsertToTable(DataSource dataSource, String tableName, Map<String,Object> data)static booleanisMysqlDbType(DbType dbType)static booleanisMysqlDbType(String dbTypeName)static booleanisMySqlDriver(String driverClassName)static booleanisOracleDbType(DbType dbType)static booleanisOracleDbType(String dbType)static booleanisPgsqlDbType(DbType dbType)static booleanisPgsqlDbType(String dbTypeName)static booleanisSqlserverDbType(DbType dbType)static booleanisSqlserverDbType(String dbTypeName)static StringmakeInsertToTableSql(String tableName, Collection<String> names)static voidprintResultSet(ResultSet rs)static voidprintResultSet(ResultSet rs, PrintStream out)static voidprintResultSet(ResultSet rs, PrintStream out, boolean printHeader, String seperator)static List<String>showTables(Connection conn, DbType dbType)
-
-
-
Method Detail
-
close
public static void close(Connection x)
-
close
public static void close(Statement x)
-
close
public static void close(ResultSet x)
-
close
public static void close(Closeable x)
-
close
public static void close(Blob x)
-
close
public static void close(Clob x)
-
printResultSet
public static void printResultSet(ResultSet rs) throws SQLException
- Throws:
SQLException
-
printResultSet
public static void printResultSet(ResultSet rs, PrintStream out) throws SQLException
- Throws:
SQLException
-
printResultSet
public static void printResultSet(ResultSet rs, PrintStream out, boolean printHeader, String seperator) throws SQLException
- Throws:
SQLException
-
getTypeName
public static String getTypeName(int sqlType)
-
getDriverClassName
public static String getDriverClassName(String rawUrl) throws SQLException
- Throws:
SQLException
-
createDriver
public static Driver createDriver(String driverClassName) throws SQLException
- Throws:
SQLException
-
createDriver
public static Driver createDriver(ClassLoader classLoader, String driverClassName) throws SQLException
- Throws:
SQLException
-
executeUpdate
public static int executeUpdate(DataSource dataSource, String sql, Object... parameters) throws SQLException
- Throws:
SQLException
-
executeUpdate
public static int executeUpdate(DataSource dataSource, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
executeUpdate
public static int executeUpdate(Connection conn, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
execute
public static void execute(DataSource dataSource, String sql, Object... parameters) throws SQLException
- Throws:
SQLException
-
execute
public static void execute(DataSource dataSource, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
execute
public static void execute(Connection conn, String sql) throws SQLException
- Throws:
SQLException
-
execute
public static void execute(Connection conn, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
executeQuery
public static List<Map<String,Object>> executeQuery(DataSource dataSource, String sql, Object... parameters) throws SQLException
- Throws:
SQLException
-
executeQuery
public static List<Map<String,Object>> executeQuery(DataSource dataSource, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
executeQuery
public static List<Map<String,Object>> executeQuery(Connection conn, String sql, List<Object> parameters) throws SQLException
- Throws:
SQLException
-
insertToTable
public static void insertToTable(DataSource dataSource, String tableName, Map<String,Object> data) throws SQLException
- Throws:
SQLException
-
insertToTable
public static void insertToTable(Connection conn, String tableName, Map<String,Object> data) throws SQLException
- Throws:
SQLException
-
makeInsertToTableSql
public static String makeInsertToTableSql(String tableName, Collection<String> names)
-
executeQuery
public static <T> void executeQuery(DataSource dataSource, ResultSetConsumer<T> consumer, String sql, Object... parameters) throws SQLException
- Throws:
SQLException
-
showTables
public static List<String> showTables(Connection conn, DbType dbType) throws SQLException
- Throws:
SQLException
-
getCreateTableScript
public static String getCreateTableScript(Connection conn, DbType dbType) throws SQLException
- Throws:
SQLException
-
getCreateTableScript
public static String getCreateTableScript(Connection conn, DbType dbType, boolean sorted, boolean simplify) throws SQLException
- Throws:
SQLException
-
isMySqlDriver
public static boolean isMySqlDriver(String driverClassName)
-
isOracleDbType
public static boolean isOracleDbType(String dbType)
-
isOracleDbType
public static boolean isOracleDbType(DbType dbType)
-
isMysqlDbType
public static boolean isMysqlDbType(String dbTypeName)
-
isMysqlDbType
public static boolean isMysqlDbType(DbType dbType)
-
isPgsqlDbType
public static boolean isPgsqlDbType(String dbTypeName)
-
isPgsqlDbType
public static boolean isPgsqlDbType(DbType dbType)
-
isSqlserverDbType
public static boolean isSqlserverDbType(String dbTypeName)
-
isSqlserverDbType
public static boolean isSqlserverDbType(DbType dbType)
-
-