接口 DbHelper
-
- 所有已知实现类:
AbstractDbHelper,H2Helper,MySQLHelper
public interface DbHelper
-
-
方法概要
所有方法 静态方法 实例方法 抽象方法 修饰符和类型 方法 说明 static com.zaxxer.hikari.HikariConfigcreateHikariConfig(String url, String username, String password)booleanexecute(String sqlStr)static booleanexecute(Connection conn, String sqlStr)执行指定sql语句ResultSetexecuteQuery(String queryStr)static ResultSetexecuteQuery(Connection conn, String queryStr)执行查询sql语句intexecuteUpdate(String updateSqlStr)static intexecuteUpdate(Connection conn, String updateSqlStr)执行指定更新语句DbConfiggetConfig()ConnectiongetConnection()static ConnectiongetConnection(DbConfig config)根据指定数据库配置,获取数据库连接的静态方法ConnectiongetConnection(String url, String username, String password)DataSourcegetDataSource()获取数据源DataSourcegetDataSource(String url)根据指定url获取数据源static DataSourcegetDataSource(String url, String username, String password)Map<String,String>getTableColumns(String tableName)获取数据库表的字段-字段类型映射Map<String,String>getTableColumns(String tableSchema, String tableName)Map<String,String>getTableColumns(Connection conn, String tableName)Map<String,String>getTableColumns(Connection conn, String tableSchema, String tableName)static Map<String,String>getTableColumns(Connection conn, Supplier<String> querySqlSupplier)获取数据库表字段-字段类型映射的静态方法voidinit(DbConfig dbConfig)voidinit(String host, Integer port, String username, String password, String dbName)voidinit(String host, String username, String password, String dbName)static <T> List<T>resultToList(ResultSet rs, Class<? extends T> clazz)voidsetConfig(DbConfig config)static <T> TsetRsDataToObject(ResultSet rs, T instance)将结果集static <T> voidsetRsDataToObject(ResultSet rs, T instance, List<String> fields)
-
-
-
方法详细资料
-
init
void init(DbConfig dbConfig)
-
getConfig
DbConfig getConfig()
-
setConfig
void setConfig(DbConfig config)
-
getConnection
Connection getConnection() throws SQLException
- 抛出:
SQLException
-
getConnection
Connection getConnection(String url, String username, String password) throws SQLException
- 抛出:
SQLException
-
getDataSource
DataSource getDataSource()
获取数据源- 返回:
- 数据源对象
-
getDataSource
DataSource getDataSource(String url)
根据指定url获取数据源- 参数:
url- 数据库连接url- 返回:
- 数据源对象
-
executeQuery
ResultSet executeQuery(String queryStr) throws SQLException
- 抛出:
SQLException
-
execute
boolean execute(String sqlStr) throws SQLException
- 抛出:
SQLException
-
executeUpdate
int executeUpdate(String updateSqlStr) throws SQLException
- 抛出:
SQLException
-
getTableColumns
Map<String,String> getTableColumns(String tableName) throws SQLException
获取数据库表的字段-字段类型映射- 参数:
tableName- 数据库表名称- 返回:
- 字段-字段类型Map映射
- 抛出:
SQLException- SQL异常
-
getTableColumns
Map<String,String> getTableColumns(Connection conn, String tableName) throws SQLException
- 抛出:
SQLException
-
getTableColumns
Map<String,String> getTableColumns(String tableSchema, String tableName) throws SQLException
- 抛出:
SQLException
-
getTableColumns
Map<String,String> getTableColumns(Connection conn, String tableSchema, String tableName) throws SQLException
- 抛出:
SQLException
-
createHikariConfig
static com.zaxxer.hikari.HikariConfig createHikariConfig(String url, String username, String password)
-
getDataSource
static DataSource getDataSource(String url, String username, String password)
-
getConnection
static Connection getConnection(DbConfig config) throws SQLException
根据指定数据库配置,获取数据库连接的静态方法- 参数:
config- 数据库配置实例- 返回:
- 抛出:
SQLException- SQL异常
-
executeQuery
static ResultSet executeQuery(Connection conn, String queryStr) throws SQLException
执行查询sql语句- 参数:
conn-queryStr-- 返回:
- 抛出:
SQLException
-
execute
static boolean execute(Connection conn, String sqlStr) throws SQLException
执行指定sql语句- 参数:
conn-sqlStr-- 返回:
- 抛出:
SQLException
-
executeUpdate
static int executeUpdate(Connection conn, String updateSqlStr) throws SQLException
执行指定更新语句- 参数:
conn-updateSqlStr-- 返回:
- 抛出:
SQLException
-
getTableColumns
static Map<String,String> getTableColumns(Connection conn, Supplier<String> querySqlSupplier) throws SQLException
获取数据库表字段-字段类型映射的静态方法- 参数:
conn- 数据库连接对象querySqlSupplier- 查询数据库表字段信息的sql供应函数- 返回:
- 字段-字段类型映射
- 抛出:
SQLException- SQL异常
-
setRsDataToObject
static <T> void setRsDataToObject(ResultSet rs, T instance, List<String> fields) throws SQLException
- 抛出:
SQLException
-
setRsDataToObject
static <T> T setRsDataToObject(ResultSet rs, T instance) throws SQLException
将结果集- 类型参数:
T-- 参数:
rs-instance-- 返回:
- 抛出:
SQLException
-
resultToList
static <T> List<T> resultToList(ResultSet rs, Class<? extends T> clazz) throws SQLException
- 抛出:
SQLException
-
-