日期:2014-05-16  浏览次数:20404 次

jdbc工具类(3)——模板类中用到接口

DAO接口:

package daoUtil;

import java.sql.SQLException;
import java.util.Collection;


public interface DAO {
 /**
  * 数据库更新操作
  * @param sql 更新操作sql语句
  * @param args sql语句参数值数组
  * @return 更新记录条数
  * @throws SQLException
  */
 public int update(String sql,Object args[])throws SQLException;
 /**
  * 数据库删除操作
  * @param sql 删除操作sql语句
  * @param args 删除操作sql语句参数值数组
  * @return 删除记录条数
  * @throws SQLException
  */
 public int delete(String sql,Object args[])throws SQLException;
 /**
  * 数据库查询操作
  * @param sql 查询操作sql语句
  * @param args 删除操作sql语句数组数值
  * @return 结果对象
  * @throws SQLException
  */
 public Object find(String sql,Object args[],RowMapper rowMapper)throws SQLException;
 /**
  * 根据数据库表名,找到该表中所有记录数
  * @param tableName 要查询的表
  * @return 表中记录数
  * @throws SQLException
  */
 public int getRecordCount(String tableName)throws SQLException;
 /**
  * 数据库插入操作
  * @param sql 插入操作 sql语句
  * @param args 插入数
  * @param primaryIndex 主键在sql语句中位置(小于-1表示用数据自动生成主键不需要插入)
  * @return 插入记录数
  * @throws SQLException
  */
 public int insert(String sql,Object args[],int primaryKeyIndex,PrimaryKeyer primaryKeyer)throws SQLException;
 /**
  * 查找符合条件所有记录
  * @param sql 查询sql语句
  * @param args 查询参数
  * @return Collection 记录集
  * @throws SQLException
  */
 public Collection ObjectList(String sql,Object args[],RowMapper rowMapper)throws SQLException;
}

?

主键生成方式接口:

package daoUtil;

import java.sql.SQLException;

public interface PrimaryKeyer {
	
	public Object getPrimaryKey()throws SQLException;
}

?

行映射器接口:

package daoUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public interface RowMapper {
	
	public Object rowMapping(ResultSet rs)throws SQLException;
}

?