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