public class StatementUtil extends Object
Constructor and Description |
---|
StatementUtil() |
public static PreparedStatement fillParams(PreparedStatement ps, Object... params) throws SQLException
ps
- PreparedStatementparams
- SQL参数PreparedStatement
SQLException
- SQL执行异常public static PreparedStatement fillParams(PreparedStatement ps, Iterable<?> params) throws SQLException
ps
- PreparedStatementparams
- SQL参数PreparedStatement
SQLException
- SQL执行异常public static PreparedStatement fillParams(PreparedStatement ps, Iterable<?> params, Map<Integer,Integer> nullTypeCache) throws SQLException
ps
- PreparedStatementparams
- SQL参数nullTypeCache
- null参数的类型缓存,避免循环中重复获取类型PreparedStatement
SQLException
- SQL执行异常public static PreparedStatement prepareStatement(Connection conn, SqlBuilder sqlBuilder) throws SQLException
conn
- 数据库连接sqlBuilder
- SqlBuilder
包括SQL语句和参数PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatement(Connection conn, String sql, Collection<Object> params) throws SQLException
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符params
- "?"对应参数列表PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatement(Connection conn, String sql, Object... params) throws SQLException
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符params
- "?"对应参数列表PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatement(boolean returnGeneratedKey, Connection conn, String sql, Object... params) throws SQLException
returnGeneratedKey
- 当为insert语句时,是否返回主键conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符params
- "?"对应参数列表PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatementForBatch(Connection conn, String sql, Object[]... paramsBatch) throws SQLException
PreparedStatement
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符paramsBatch
- "?"对应参数批次列表PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatementForBatch(Connection conn, String sql, Iterable<Object[]> paramsBatch) throws SQLException
PreparedStatement
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符paramsBatch
- "?"对应参数批次列表PreparedStatement
SQLException
- SQL异常public static PreparedStatement prepareStatementForBatch(Connection conn, String sql, Iterable<String> fields, Entity... entities) throws SQLException
PreparedStatement
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符fields
- 字段列表,用于获取对应值entities
- "?"对应参数批次列表PreparedStatement
SQLException
- SQL异常public static CallableStatement prepareCall(Connection conn, String sql, Object... params) throws SQLException
conn
- 数据库连接sql
- SQL语句,使用"?"做为占位符params
- "?"对应参数列表CallableStatement
SQLException
- SQL异常public static Long getGeneratedKeyOfLong(Statement ps) throws SQLException
ps
- PreparedStatementSQLException
- SQL执行异常public static List<Object> getGeneratedKeys(Statement ps) throws SQLException
ps
- PreparedStatementSQLException
- SQL执行异常public static <T> T getGeneratedKeys(Statement statement, RsHandler<T> rsHandler) throws SQLException
RsHandler
处理后返回T
- 自定义主键类型statement
- Statement
rsHandler
- 主键结果集处理器SQLException
- SQL执行异常public static int getTypeOfNull(PreparedStatement ps, int paramIndex)
Types.VARCHAR
ps
- Statement
paramIndex
- 参数位置,第一位从1开始Types.VARCHAR
public static void setParam(PreparedStatement ps, int paramIndex, Object param) throws SQLException
PreparedStatement
设置单个参数ps
- PreparedStatement
paramIndex
- 参数位置,从1开始param
- 参数SQLException
- SQL异常Copyright © 2024. All rights reserved.