public class SqliteHelper extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
closeAll()
关闭所有连接池
|
int |
executeInsertOrUpdate(String tableName,
Map<String,Object> param)
执行数据库更新sql语句
|
String |
executeQuery(String sql)
简单查询某个字段
|
<T> T |
executeQuery(String sql,
Class<T> clazz)
执行sql查询,适用单条结果集
|
<T> T |
executeQuery(String sql,
ResultSetExtractor<T> rse)
执行sql查询
|
<T> List<T> |
executeQuery(String sql,
RowMapper<T> rm)
执行select查询,返回结果列表
|
<T> List<T> |
executeQueryList(String sql,
Class<T> clazz)
执行select查询,返回结果列表
|
void |
executeUpdate(List<String> sqls)
执行数据库更新 sql List
|
void |
executeUpdate(String... sqls)
执行多个sql更新语句
|
int |
executeUpdate(String sql)
执行数据库更新sql语句
|
int |
executeUpdate(String sql,
Object[] args)
使用预编译语句执行更新
|
Connection |
getConnection()
获取数据库连接
|
static SqliteHelper |
getInstance(String dbFilePath)
获取SqliteHelper实例(单例模式)
|
void |
initializeDatabase(String tableName,
String schemaResourcePath)
初始化数据库表结构
|
public static SqliteHelper getInstance(String dbFilePath) throws SQLException, ClassNotFoundException
dbFilePath - sqlite db 文件路径SQLException - SQL异常ClassNotFoundException - 类未找到异常public Connection getConnection() throws SQLException
SQLException - SQL异常public <T> T executeQuery(String sql, ResultSetExtractor<T> rse) throws SQLException
sql - sql select 语句rse - 结果集处理类对象SQLException - SQL异常public <T> List<T> executeQuery(String sql, RowMapper<T> rm) throws SQLException
sql - sql select 语句rm - 结果集的行数据处理类对象SQLException - SQL异常public String executeQuery(String sql) throws SQLException
sql - SQL查询语句SQLException - SQL异常public int executeUpdate(String sql) throws SQLException
sql - SQL更新语句SQLException - SQL异常public void executeUpdate(String... sqls) throws SQLException
sqls - SQL更新语句数组SQLException - SQL异常public void executeUpdate(List<String> sqls) throws SQLException
sqls - sql列表SQLException - SQL异常public <T> List<T> executeQueryList(String sql, Class<T> clazz) throws SQLException, IllegalAccessException, InstantiationException
sql - sql select 语句clazz - 实体泛型SQLException - 异常信息IllegalAccessException - 非法访问异常InstantiationException - 实例化异常public <T> T executeQuery(String sql, Class<T> clazz) throws SQLException, IllegalAccessException, InstantiationException
sql - sql select 语句clazz - 结果集处理类对象SQLException - SQL异常IllegalAccessException - 非法访问异常InstantiationException - 实例化异常public int executeInsertOrUpdate(String tableName, Map<String,Object> param) throws SQLException
tableName - 表名param - key-value键值对,key:表中字段名,value:值SQLException - SQL异常public int executeUpdate(String sql, Object[] args) throws SQLException
sql - SQL语句args - 参数SQLException - SQL异常public void initializeDatabase(String tableName, String schemaResourcePath) throws SQLException
SQLExceptionpublic static void closeAll()
Copyright © 2025. All rights reserved.