Class JdbcUtil

java.lang.Object
org.huiche.jdbc.support.JdbcUtil

public final class JdbcUtil extends Object
Jdbc工具类
Author:
Maning
  • Method Details

    • applyParameter

      public static <T> void applyParameter(PreparedStatement ps, int parameterIndex, T val, Configuration configuration) throws SQLException
      设置ps的参数
      Type Parameters:
      T - 参数类型
      Parameters:
      ps - ps对象
      parameterIndex - 参数下标
      val - 值
      configuration - 配置
      Throws:
      SQLException - SQL异常
      HcJdbcException - 如果遇到无法写入的类型的值且未提供对应转换器
    • applyParameters

      public static void applyParameters(PreparedStatement ps, List<?> params, Configuration configuration) throws SQLException
      批量设置ps的参数, 如果为null直接设置null
      Parameters:
      ps - ps对象
      params - 参数
      configuration - 配置
      Throws:
      SQLException - SQL异常
    • closeResultSet

      public static void closeResultSet(ResultSet rs)
      关闭结果集
      Parameters:
      rs - 结果集
    • closeStatement

      public static void closeStatement(PreparedStatement ps)
      关闭ps对象
      Parameters:
      ps - ps对象
    • resolveColumnVal

      public static <T> T resolveColumnVal(Type type, ResultSet rs, int columnIndex, Configuration configuration) throws SQLException
      解析列的值
      Type Parameters:
      T - 列的类型
      Parameters:
      type - 列类型
      rs - jdbc结果集
      columnIndex - 列下标,从1开始
      configuration - 配置
      Returns:
      列的值
      Throws:
      SQLException - 原生sql异常
      HcJdbcException - 如果遇到无法解析类型的且未提供对应转换器
    • resolveColumnVal

      public static <T> T resolveColumnVal(Type type, ResultSet rs, int columnIndex, Configuration configuration, boolean handleNull) throws SQLException
      解析列的值
      Type Parameters:
      T - 列的类型
      Parameters:
      type - 列类型
      rs - jdbc结果集
      columnIndex - 列下标,从1开始
      configuration - 配置
      handleNull - 是否处理null值为空集合|数组|map
      Returns:
      列的值
      Throws:
      SQLException - 原生sql异常
      HcJdbcException - 如果遇到无法解析类型的且未提供对应转换器
    • stream

      public static <T> Stream<T> stream(ResultSet rs, Configuration configuration, RowMapper<T> rowMapper, Integer estimateSize, Runnable onClose)
      构建stream查询
      Type Parameters:
      T - 类型
      Parameters:
      rs - rs
      configuration - 配置
      rowMapper - 行转换器
      estimateSize - 预期大小
      onClose - 关闭回调
      Returns:
      stream对象