com.xiaoleilu.hutool.db
类 DbUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.db.DbUtil

public class DbUtil
extends Object

数据库操作工具类

作者:
Luxiaolei

方法摘要
static String buildEqualsWhere(Entity entity, List<Object> paramValues)
          构件相等条件的where语句
如果没有条件语句,泽返回空串,表示没有条件
static void close(Object... objsToClose)
          连续关闭一系列的SQL相关对象
这些对象必须按照顺序关闭,否则会出错。
static void fillParams(PreparedStatement ps, Object... params)
          填充SQL的参数。
static String[] getColumnNames(DataSource ds, String tableName)
          获得表的所有列名
static String[] getColumnNames(ResultSet rs)
          获得结果集的所有列名
static Long getGeneratedKey(PreparedStatement ps)
          获得自增键的值
static DataSource getJndiDs(String jndiName)
          获得JNDI数据源
static Table getTableMeta(DataSource ds, String tableName)
          获得表的元信息
static List<String> getTables(DataSource ds)
          获得所有表名
static String identifyDriver(Connection conn)
          识别JDBC驱动名
static String identifyDriver(DataSource ds)
          识别JDBC驱动名
static String identifyDriver(String nameContainsProductInfo)
          识别JDBC驱动名
static SqlRunner newSqlRunner(DataSource ds)
          实例化一个新的SQL运行对象
static SqlRunner newSqlRunner(DataSource ds, Dialect dialect)
          实例化一个新的SQL运行对象
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

方法详细信息

newSqlRunner

public static SqlRunner newSqlRunner(DataSource ds)
实例化一个新的SQL运行对象

参数:
ds - 数据源
返回:
SQL执行类

newSqlRunner

public static SqlRunner newSqlRunner(DataSource ds,
                                     Dialect dialect)
实例化一个新的SQL运行对象

参数:
ds - 数据源
dialect - SQL方言
返回:
SQL执行类

close

public static void close(Object... objsToClose)
连续关闭一系列的SQL相关对象
这些对象必须按照顺序关闭,否则会出错。

参数:
objsToClose - 需要关闭的对象

getJndiDs

public static DataSource getJndiDs(String jndiName)
获得JNDI数据源

参数:
jndiName - JNDI名称
返回:
数据源

getTables

public static List<String> getTables(DataSource ds)
获得所有表名


getColumnNames

public static String[] getColumnNames(ResultSet rs)
获得结果集的所有列名

参数:
rs - 结果集
返回:
列名数组

getColumnNames

public static String[] getColumnNames(DataSource ds,
                                      String tableName)
获得表的所有列名

参数:
ds - 数据源
tableName - 表名
返回:
列数组
抛出:
SQLException

getTableMeta

public static Table getTableMeta(DataSource ds,
                                 String tableName)
获得表的元信息

参数:
ds - 数据源
tableName - 表名
返回:
Table对象

fillParams

public static void fillParams(PreparedStatement ps,
                              Object... params)
                       throws SQLException
填充SQL的参数。

参数:
ps - PreparedStatement
params - SQL参数
抛出:
SQLException

getGeneratedKey

public static Long getGeneratedKey(PreparedStatement ps)
                            throws SQLException
获得自增键的值

参数:
ps - PreparedStatement
返回:
自增键的值
抛出:
SQLException

buildEqualsWhere

public static String buildEqualsWhere(Entity entity,
                                      List<Object> paramValues)
构件相等条件的where语句
如果没有条件语句,泽返回空串,表示没有条件

参数:
entity - 条件实体
paramValues - 条件值得存放List
返回:
带where关键字的SQL部分

identifyDriver

public static String identifyDriver(String nameContainsProductInfo)
识别JDBC驱动名

参数:
nameContainsProductInfo - 包含数据库标识的字符串
返回:
驱动

identifyDriver

public static String identifyDriver(DataSource ds)
识别JDBC驱动名

参数:
ds - 数据源
返回:
驱动

identifyDriver

public static String identifyDriver(Connection conn)
识别JDBC驱动名

参数:
conn - 数据库连接对象
返回:
驱动


Copyright © 2014. All rights reserved.