⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqldb.java

📁 本人课程设计时做的一个用struts框架实现的基于cmmi2的项目管理系统的原型。还有部分功能尚未实现
💻 JAVA
字号:
package com.cmmi2pms.common.comdb;

import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * <p>The entrance of the comdb.This class provides some interfaces
 * 	which execute the sql statement
 * 
 * @author xunzy
 * @version 0.01
 *
 */
public class SqlDB {
	
	//Private variables to hold objects.
	private SqlStatement ss= null;
	private PooledConnectionMgr pool = null;
	private Connection conn=null;
	
	/**
	 * Default constructor 
	 */
	public SqlDB() throws Exception
	{
		pool = PooledConnectionMgr.getInstance();
		init();
	}
	/**
	 * Initialization to open a connection and pass it to the SqlStatement object.
	 * 
	 * @throws Exception
	 */
	private void init() throws Exception
	{
		conn = pool.getConnection();
		ss = new SqlStatement();
		ss.setConnection(conn);
	}
	
	/**
	 * Connect to database
	 * @throws Exception
	 */
	public void connect() throws Exception
	{
		conn = pool.getConnection();
		if(ss == null)
		{
			ss = new SqlStatement();
		}
		ss.setConnection(conn);
	}
	
	/**
	 * Method to execute SELECT SQL statements supplied as a parameter
	 * 
	 * @param sql
	 * @return ResulstSet
	 * @throws SQLException
	 */
	public ResultSet executeQuery(String sql) throws SQLException
	{
		return ss.executeQuery(sql);
	}
	
	/**
	 * Method to execute SELECT SQL statements
	 * 
	 * @return ResulstSet
	 * @throws SQLException
	 */
	public ResultSet executeQuery() throws SQLException
	{
		return ss.executeQuery();
	}
	
	/**
	 * Method to execute all SQL statements except SELECT
	 * 
	 * @return int The counts which the sql updates , deletes or inserts
	 * @throws SQLException
	 */
	public int execute() throws SQLException
	{
		return ss.execute();
	}
	
	/**
	 * Method to execute all SQL statements except SELECT
	 * 
	 * @param sql
	 * @return int The counts which the sql updates , deletes or inserts
	 * @throws SQLException
	 */
	public int execute(String sql) throws SQLException
	{
		return ss.execute(sql);
	}
	
	/**
	 * Sets the SQL string in the SqlStatement object
	 * 
	 * @param sql
	 * @throws SQLException
	 */
	public void setSql(String sql) throws SQLException
	{
		ss.setSql(sql);
	}
	
	/**
	 * Clears the SqlStatement object
	 * 
	 * @throws Exception
	 */
	public void reset() throws Exception
	{
		//Set the reference to the ss to null;
		ss = null;
		//Reinitialize object
		init();
	}
	
	/**
	 * Close database connection
	 * 
	 * @throws SQLException
	 */
	public void close() throws SQLException
	{
		if(ss!=null)
		{
			ss.close();
		}
		if(conn!=null)
		{
			pool.close(conn);
		}
	}
	
	/**
	 * Set a String value in a PreparedStatement
	 * 
	 * @param index
	 * @param value
	 * @throws SQLException
	 */
	public void setString(int index, String value) throws SQLException
	{
		ss.setString(index,value);
	}
	
	/**
	 * Set an int value in a PreparedStatement
	 * 
	 * @param index
	 * @param value
	 * @throws SQLException
	 */
	public void setInt(int index, int value) throws SQLException
	{
		ss.setInt(index,value);
	}
	
	/**
	 * Set a double value in a PreparedStatement
	 * 
	 * @param index
	 * @param value
	 * @throws SQLException
	 */
	public void setDouble(int index, double value) throws SQLException
	{
		ss.setDouble(index,value);
	}
	
	/**
	 * Set a Date value in a PreparedStatement]
	 * 
	 * @param index
	 * @param value
	 * @throws SQLException
	 */
	public void setDate(int index, Date value) throws SQLException
	{
		ss.setDate(index,value);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -