`

DBUTIL

 
阅读更多

package thtf.ebuilder.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Map;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

/**
 * 采用Apache dbutils操作数据库的工具类,可采用Spring注入DataSource
 * 
 * <pre>
 * 方式一:使用默认的数据源(jdbc/eBuilder)
 *    DBUtil tool=new DBUtil();///操作完毕默认关闭连接
 *    DBUtil tool=new DBUtil(false);//设置不关闭连接
 *    使用完之后关闭连接 tool.close();
 * 方式二:使用自定义数据源
 *    String dataSourceName=&quot;&quot;;
 *    DBUtil tool=new DBUtil(dataSourceName);///操作完毕默认关闭连接
 *    DBUtil tool=new DBUtil(dataSourceName,false);//操作完毕不关闭连接
 *    使用完之后关闭连接 tool.close();
 * 方式三:使用自定义数据源
 *    java.sql.DataSource dataSource=null;
 *    DBUtil tool=new DBUtil(dataSource);///操作完毕默认关闭连接
 *    DBUtil tool=new DBUtil(dataSource,false);//操作完毕不关闭连接
 *    使用完之后关闭连接 tool.close();
 * 方式四:使用指定的数据库连接
 *    java.sql.connection=null;
 *    DBUtil tool=new DBUtil(connection);///操作完毕默认关闭连接
 *    DBUtil tool=new DBUtil(dataSource,false);//操作完毕不关闭连接
 *    使用完之后关闭连接 tool.close();
 * </pre>
 * 
 * @author 杨伦亮 Jun 13, 2011
 */
public class DBUtil {
	// Spring可注入DataSource
	public DataSource dataSource = null;
	private Connection connection = null;
	// ***********静态变量
	private boolean CloseConnection = true;
	public static final String DEFAULT_JNDI = "jdbc/eBuilder";
	/**
	 * 采用默认数据库连接(jdbc/eBuilder)操作完毕默认关闭连接
	 */
	public DBUtil() {
	}
	/**
	 * 采用默认数据库连接(jdbc/eBuilder)可指定是否操作完毕关闭连接
	 */
	public DBUtil(boolean closeConnection) {
		CloseConnection = closeConnection;
	}
	/**
	 * 采用指定的数据库连接,操作完毕默认关闭连接
	 * 
	 * @param connection
	 */
	public DBUtil(Connection connection) {
		this.connection = connection;
	}
	/**
	 * 采用指定的数据库连接,可指定是否操作完毕关闭连接
	 * 
	 * @param connection
	 * @param closeConnection
	 */
	public DBUtil(Connection connection, boolean closeConnection) {
		this.connection = connection;
		CloseConnection = closeConnection;
	}
	/**
	 * 采用指定的DataSource操作数据库,操作完毕默认关闭连接
	 * 
	 * @param dataSource
	 */
	public DBUtil(DataSource dataSource) {
		try {
			this.dataSource = dataSource;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 采用指定的DataSource操作数据库,可指定是否操作完毕关闭连接
	 * 
	 * @param dataSource
	 * @param closeConnection
	 */
	public DBUtil(DataSource dataSource, boolean closeConnection) {
		try {
			this.dataSource = dataSource;
			CloseConnection = closeConnection;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            An array of query replacement parameters. Each row in this
	 *            array is one set of batch replacement values.
	 * @return The number of rows updated per statement.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public int[] batch(String sql, Object[][] params) throws Exception {
		Connection conn = this.getConnection();
		int[] rows = null;
		QueryRunner run = new QueryRunner();
		try {
			rows = run.batch(conn, sql, params);
		} finally {
			close(conn);
		}

		return rows;
	}
	/**
	 * 关闭连接
	 * 
	 * @param connection
	 */
	public void close() {
		DbUtils.closeQuietly(connection);
	}
	private void close(Connection connection){
		if(CloseConnection){
			DbUtils.closeQuietly(connection);
		}
	}
	/**
	 * Executes the given INSERT, UPDATE, or DELETE SQL statement without any
	 * replacement parameters.
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @return The number of rows updated.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public int executeUpdate(String sql) throws Exception {
		Connection conn = this.getConnection();
		int rows = 0;
		QueryRunner run = new QueryRunner();
		try {
			rows = run.update(conn, sql);
		} finally {
			close(conn);
		}
		return rows;
	}

	/**
	 * Executes the given INSERT, UPDATE, or DELETE SQL statement with a single
	 * replacement parameter.
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return The number of rows updated.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public int executeUpdate(String sql, Object param) throws Exception {
		Connection conn = this.getConnection();
		int rows = 0;
		QueryRunner run = new QueryRunner();
		try {
			rows = run.update(conn, sql, param);
		} finally {
			close(conn);
		}

		return rows;
	}

	/**
	 * Executes the given INSERT, UPDATE, or DELETE SQL statement.
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param params
	 *            Initializes the PreparedStatement's IN (i.e. '?') parameters.
	 * @return The number of rows updated.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public int executeUpdate(String sql, Object[] params) throws Exception {
		Connection conn = this.getConnection();
		int rows = 0;
		QueryRunner run = new QueryRunner();
		try {

			rows = run.update(conn, sql, params);

		} finally {
			close(conn);
		}

		return rows;
	}
	/**
	 * 获得数据库的连接
	 * 
	 * @return Connection
	 */
	public Connection getConnection() throws Exception {
		// 如果Connection为空
		Class.forName("net.sourceforge.jtds.jdbc.Driver");
		connection = DriverManager
				.getConnection(
						"jdbc:jtds:sqlserver://localhost:1433;DatabaseName=website;useLOBs=false",
						"sa", "sa1");
		if (connection == null || connection.isClosed()) {
			// 如果dataSource没有注入就采用默认的
			if (dataSource == null) {
				dataSource = (DataSource) new InitialContext()
						.lookup(DEFAULT_JNDI);
			}
			connection = dataSource.getConnection();
		}
		return connection;
	}
	public DataSource getDataSource() {
		return dataSource;
	}
	/**
	 * Get Maximun Field Value Named 'sFldName' of Table 'sTblName'
	 * 
	 * @param sTblName
	 *            The Table Name
	 * @param sFldName
	 *            The Field Name
	 * @return Maximum Id
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public int getMaxId(String sTableName, String sFieldName) {
		int iRes = -1;
		String sql = "SELECT MAX(" + sFieldName + ") AS maxid FROM "
				+ sTableName;
		Map result;
		try {
			result = queryToMap(sql);
			if (result.get("maxid") != null) {
				iRes = Integer.parseInt(result.get("maxid").toString()) + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return iRes;
	}
	/**
	 * Execute an SQL SELECT query without any replacement parameters and place
	 * the column values from the first row in an Object[]. Usage Demo:
	 * 
	 * <pre>
	 * Object[] result = searchToArray(sql);
	 * if (result != null) {
	 * 	for (int i = 0; i &lt; result.length; i++) {
	 * 		System.out.println(result[i]);
	 * 	}
	 * }
	 * </pre>
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @return An Object[] or null if there are no rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object[] queryToArray(String sql) throws Exception {
		Connection conn = this.getConnection();
		Object[] result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayHandler();
		try {
			result = (Object[]) run.query(conn, sql, h);
		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * place the column values from the first row in an Object[].
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return An Object[] or null if there are no rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object[] queryToArray(String sql, Object param) throws Exception {
		Connection conn = this.getConnection();
		Object[] result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayHandler();
		try {
			result = (Object[]) run.query(conn, sql, param, h);
		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL query and place the column values from the
	 * first row in an Object[].
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return An Object[] or null if there are no rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object[] queryToArray(String sql, Object[] params) throws Exception {
		Connection conn = this.getConnection();
		Object[] result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayHandler();
		try {
			result = (Object[]) run.query(conn, sql, params, h);
		} finally {
			close(conn);
		}
		return result;
	}

	/**
	 * Execute an SQL SELECT query without any replacement parameters and place
	 * the ResultSet into a List of Object[]s Usage Demo:
	 * 
	 * <pre>
	 * ArrayList result = queryToArrayList(sql);
	 * Iterator iterator = result.iterator();
	 * while (iterator.hasNext()) {
	 * 	Object[] temp = (Object[]) iterator.next();
	 * 	for (int i = 0; i &lt; temp.length; i++) {
	 * 		System.out.println(temp[i]);
	 * 	}
	 * }
	 * </pre>
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @return A List of Object[]s, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToArrayList(String sql) throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayListHandler();
		try {
			result = (ArrayList) run.query(conn, sql, h);
		} finally {
			close(conn);
		}
		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * place the ResultSet into a List of Object[]s
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return A List of Object[]s, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToArrayList(String sql, Object param)
			throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayListHandler();
		try {
			result = (ArrayList) run.query(conn, sql, param, h);
		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL query and place the ResultSet into a List
	 * of Object[]s
	 * 
	 * @param sql
	 *            The SQL statement to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return A List of Object[]s, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToArrayList(String sql, Object[] params)
			throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new ArrayListHandler();
		try {

			result = (ArrayList) run.query(conn, sql, params, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Execute an SQL SELECT query without any replacement parameters and
	 * converts the first ResultSet into a Map object. Usage Demo:
	 * 
	 * <pre>
	 * Map result = queryToMap(sql);
	 * System.out.println(map.get(columnName));
	 * </pre>
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @return A Map with the values from the first row or null if there are no
	 *         rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Map queryToMap(String sql) throws Exception {
		Connection conn = this.getConnection();
		Map result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapHandler();
		try {

			result = (Map) run.query(conn, sql, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * converts the first ResultSet into a Map object.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return A Map with the values from the first row or null if there are no
	 *         rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Map queryToMap(String sql, Object param) throws Exception {
		Connection conn = this.getConnection();
		Map result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapHandler();
		try {
			result = (Map) run.query(conn, sql, param, h);

		} finally {
			close(conn);
		}
		return result;
	}
	/**
	 * Executes the given SELECT SQL query and converts the first ResultSet into
	 * a Map object.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return A Map with the values from the first row or null if there are no
	 *         rows in the ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Map queryToMap(String sql, Object[] params) throws Exception {
		Connection conn = this.getConnection();
		Map result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapHandler();
		try {

			result = (Map) run.query(conn, sql, params, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Execute an SQL SELECT query without any replacement parameters and
	 * converts the ResultSet into a List of Map objects. Usage Demo:
	 * 
	 * <pre>
	 * ArrayList result = queryToMapList(sql);
	 * Iterator iterator = result.iterator();
	 * while (iterator.hasNext()) {
	 * 	Map map = (Map) iterator.next();
	 * 	System.out.println(map.get(columnName));
	 * }
	 * </pre>
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @return A List of Maps, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToMapList(String sql) throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapListHandler();
		try {

			result = (ArrayList) run.query(conn, sql, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * converts the ResultSet into a List of Map objects.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return A List of Maps, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToMapList(String sql, Object param) throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapListHandler();
		try {
			result = (ArrayList) run.query(conn, sql, param, h);
		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL query and converts the ResultSet into a
	 * List of Map objects.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return A List of Maps, never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToMapList(String sql, Object[] params)
			throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new MapListHandler();
		try {

			result = (ArrayList) run.query(conn, sql, params, h);

		} finally {
			close(conn);
		}

		return result;
	}
	/**
	 * Execute an SQL SELECT query without any replacement parameters and
	 * Convert the first row of the ResultSet into a bean with the Class given
	 * in the parameter. Usage Demo:
	 * 
	 * <pre>
	 * String sql = &quot;SELECT * FROM test&quot;;
	 * Test test = (Test) queryToBean(Test.class, sql);
	 * if (test != null) {
	 * 	System.out.println(&quot;test:&quot; + test.getPropertyName());
	 * }
	 * </pre>
	 * 
	 * @param type
	 *            The Class of beans.
	 * @param sql
	 *            The SQL to execute.
	 * @return An initialized JavaBean or null if there were no rows in the
	 *         ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object queryToBean(Class type, String sql) throws Exception {
		Connection conn = this.getConnection();
		Object result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanHandler(type);
		try {

			result = run.query(conn, sql, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * Convert the first row of the ResultSet into a bean with the Class given
	 * in the parameter.
	 * 
	 * @param type
	 *            The Class of beans.
	 * @param sql
	 *            The SQL to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return An initialized JavaBean or null if there were no rows in the
	 *         ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object queryToBean(Class type, String sql, Object param)
			throws Exception {
		Connection conn = this.getConnection();
		Object result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanHandler(type);
		try {

			result = run.query(conn, sql, param, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL query and Convert the first row of the
	 * ResultSet into a bean with the Class given in the parameter.
	 * 
	 * @param type
	 *            The Class of beans.
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return An initialized JavaBean or null if there were no rows in the
	 *         ResultSet.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public Object queryToBean(Class type, String sql, Object[] params)
			throws Exception {
		Connection conn = this.getConnection();
		Object result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanHandler(type);
		try {
			result = run.query(conn, sql, params, h);
		} finally {
			close(conn);
		}
		return result;
	}

	/**
	 * Execute an SQL SELECT query without any replacement parameters and
	 * Convert the ResultSet rows into a List of beans with the Class given in
	 * the parameter. Usage Demo:
	 * 
	 * <pre>
	 * ArrayList result = queryToBeanList(Test.class, sql);
	 * Iterator iterator = result.iterator();
	 * while (iterator.hasNext()) {
	 * 	Test test = (Test) iterator.next();
	 * 	System.out.println(test.getPropertyName());
	 * }
	 * </pre>
	 * 
	 * @param type
	 *            The Class that objects returned from handle() are created
	 *            from.
	 * @param sql
	 *            The SQL to execute.
	 * @return A List of beans (one for each row), never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToBeanList(Class type, String sql) throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanListHandler(type);
		try {
			result = (ArrayList) run.query(conn, sql, h);
		} finally {
			close(conn);
		}
		return result;
	}

	/**
	 * Executes the given SELECT SQL with a single replacement parameter and
	 * Convert the ResultSet rows into a List of beans with the Class given in
	 * the parameter.
	 * 
	 * @param type
	 *            The Class that objects returned from handle() are created
	 *            from.
	 * @param sql
	 *            The SQL to execute.
	 * @param param
	 *            The replacement parameter.
	 * @return A List of beans (one for each row), never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToBeanList(Class type, String sql, Object param)
			throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanListHandler(type);
		try {

			result = (ArrayList) run.query(conn, sql, param, h);

		} finally {
			close(conn);
		}

		return result;
	}

	/**
	 * Executes the given SELECT SQL query and Convert the ResultSet rows into a
	 * List of beans with the Class given in the parameter.
	 * 
	 * @param type
	 *            The Class that objects returned from handle() are created
	 *            from.
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this
	 *            array.
	 * @return A List of beans (one for each row), never null.
	 */
	@SuppressWarnings({"unchecked", "deprecation"})
	public ArrayList queryToBeanList(Class type, String sql, Object[] params)
			throws Exception {
		Connection conn = this.getConnection();
		ArrayList result = null;
		QueryRunner run = new QueryRunner();
		ResultSetHandler h = new BeanListHandler(type);
		try {

			result = (ArrayList) run.query(conn, sql, params, h);

		} finally {
			close(conn);
		}

		return result;
	}
	/**
	 * 回滚事务关关闭连接
	 * 
	 * @param connection
	 */
	public static void rolbackAndClose(Connection connection) {
		try {
			DbUtils.rollbackAndClose(connection);
		} catch (Exception e) {
		}
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	public static void main(String[] args) {
		Connection connection=null;
		try{
			DBUtil tool=new DBUtil(false);
			connection=tool.getConnection();
			System.out.println("step1:连接是否已经获得?");
			System.out.println(((connection!=null)||(!connection.isClosed())));
			
			System.out.println("\nstep2:尝试关闭本地连接...\nconnection.close();");
			connection.close();
			
			System.out.println("\nstep3:本地连接是否关闭?\t"+(connection.isClosed()));
			System.out.println("DBUtil中的连接是否关闭?\t");
			tool.conncectionState();	
			
			System.out.println("\nstep4:关闭本地连接之后,DBUtil中的连接是否关闭?");
			tool.conncectionState();
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				if(connection!=null){
					connection.close();
				}
			}catch (Exception e) {
			}
			System.out.println("\nstep5:测试数据库连接完毕!");
		}
	}
	public void conncectionState() {
		try{
			System.out.println("连接是否为空:\t"+(connection==null));
			System.out.println("连接是否关闭:\t"+(connection.isClosed()));
		}catch (Exception e) {
		}
	}
}
 
分享到:
评论

相关推荐

    Dbutil使用jar包

    Dbutil,全称为Apache Commons DbUtils,是一款由Apache软件基金会开发的开源Java工具包,它为JDBC(Java Database Connectivity)提供了一层简单的封装,旨在让数据库操作变得更加便捷且不易出错。DbUtil的设计目标...

    DBUtil工具类jar包

    DBUtil工具类是Java开发中常见的一种数据库操作辅助类,它的主要目的是为了简化数据库的CRUD(创建、读取、更新、删除)操作,提高开发效率。DBUtil通常集成了连接池技术,如Druid、C3P0或HikariCP等,以优化数据库...

    DBUtil(ASP。NET数据库连接工具类)

    DBUtil 是一个在ASP.NET开发环境中常用的数据库连接工具类,它的设计目的是为了简化数据库操作,减少程序员编写重复的连接和断开数据库的代码,从而提高开发效率和代码的可维护性。通过使用DBUtil,开发者可以快速地...

    DBUtil工具类

    DBUtil工具类是Java开发中常见的一种设计,用于简化数据库操作,提高开发效率。它通常包含了一系列静态方法,可以执行SQL语句,处理结果集,进行数据库连接的创建、管理和关闭等。这样的工具类在DAO(数据访问对象)...

    韩顺平SqlHelper,DBUtil工具类

    韩顺平SqlHelper和DBUtil工具类是为了解决这一问题而设计的,它们提供了一种方便的方式来处理SQL Server数据库。这两个工具类是非静态的,这意味着它们可以被实例化并复用,从而避免了静态类可能带来的线程安全问题...

    DButil 封装 包括模糊查询 分页Count 普通增删改查方法

    DButil 是一个数据库操作工具类,它封装了常见的SQL操作,如模糊查询、分页查询、数据的增删改查等。这样的工具类在实际开发中非常常见,它简化了数据库交互的代码,提高了开发效率。下面将详细介绍DButil封装中的...

    Laravel开发-dbutil

    在Laravel框架中,`dbutil`通常指的是数据库操作的实用工具或自定义库,它扩展了Laravel原生的数据库处理能力,提供了一系列便利的方法,以帮助开发者更高效地进行数据操作。本文将深入探讨Laravel开发中的`dbutil`...

    DBUtil使用于javaWeb连接池c3p0

    在这个场景下,`DBUtil` 类被用来简化与C3P0连接池的交互,以方便地进行数据库操作。下面我们将详细探讨`DBUtil` 的使用方法以及C3P0连接池的工作原理。 1. **C3P0简介** C3P0是由Miguel Grinberg创建的一个开源...

    DbUtil和tomcat数据源配置实例

    `DbUtil`是一个常见的数据库操作工具类,用于简化数据库连接的创建、关闭等操作,而Tomcat数据源(JNDI数据源)是应用服务器(如Tomcat)提供的一种管理数据库连接的机制。这两种方式都能有效地管理和优化数据库连接...

    dbutil-java于sql的连接

    在Java编程中,数据库操作是不可或缺的一部分,而`dbutil`通常是指用于简化数据库操作的工具包或类库。在本场景中,我们讨论的是如何使用Java与SQL Server进行连接,以及可能涉及到的XML配置文件的修改。下面将详细...

    dbutil+c3p0

    "dbutil+c3p0"这个组合涉及到两个关键组件:DBUtils和C3P0,它们都是Java数据库连接(JDBC)的辅助工具,使得数据库操作更加高效和便捷。下面将详细阐述这两个工具以及它们在实际应用中的作用。 首先,DBUtils是...

    通用数据库分页 扩展dbutil (附代码下载)

    本主题将深入探讨“通用数据库分页”以及如何通过扩展dbutil工具来实现这一功能。我们将从以下几个方面展开讨论: 1. **数据库分页原理**: 数据库分页的基本思想是将数据分成若干个页,每次只返回用户请求的一页...

    DBUtil包连接池

    DBUtil类内部包含有连接池创建和连接池的关闭,下载后记得修改URL

    数据库操作的DBUtil包,SQL2005驱动包,ASCII编码字符集

    在IT行业中,数据库操作是核心任务之一,而DBUtil包作为一种通用的数据库操作工具,能够极大地简化编程工作。本文将详细解析DBUtil包的使用、SQL Server 2005驱动包的功能,以及ASCII编码字符集的相关知识。 首先,...

    补丁MySQL+JDBC+DBUtil+c3p0史上最全数据库讲义.rar

    DBUtil和c3p0则是两个在Java开发中常用的数据库连接池工具,它们可以提高数据库操作的效率和性能。 **MySQL** MySQL是一个开源、免费的SQL数据库,提供了强大的数据存储和查询能力。它的优点包括高效、稳定、易于...

    Struts2+displaytag+dbutil

    Struts2、DisplayTag和DbUtil是Java Web开发中常用的三个框架或库,它们在构建高效、可维护的Web应用程序中发挥着重要作用。 Struts2是Apache软件基金会下的一个开源MVC(Model-View-Controller)框架,它提供了一...

    .NET连接Mysql - MYSQL4dotNet-DBUtil

    `.NET连接Mysql - MYSQL4dotNet-DBUtil`这个项目是专为使用C#语言在Windows CE(Wince)环境下连接MySQL数据库而设计的一个实用工具类库。`DBUtil.cs`文件很可能是这个库的核心组件,它提供了方便的方法来执行SQL...

    DBUtil——连接SQL (JDBC使用)

    本教程将围绕"DBUtil",一个简单的JDBC工具类,来介绍如何使用配置文件进行SQL连接和数据库的基本操作。这个工具类适用于初学者学习数据库连接管理。 首先,我们来看"db.properties"文件,这是用来存储数据库连接...

    DBUtil.java类

    DBUtil的类,在WEB开发当中有许多项目都需要用它,可以不用重复写,这样很方便

    Oracle JDBC DbUtil jdbc数据库连接

    Oracle JDBC DbUtil 是一个用于简化Java应用程序与Oracle数据库交互的工具包。这个工具包通过提供便利的类和方法,使得开发者能够更高效地执行SQL语句、管理数据库连接以及处理结果集。在给定的文件中,我们可以看到...

Global site tag (gtag.js) - Google Analytics