jdbcTools

制作jdbc的工具类  
  1 插入
  2 查询所有
  3 根据主键查询
  4 根据给定非空字段等值查询
  5 分页查询 
  6 根据给定的ids主键集合查询
  7 根据指定sql语句查询 返回List<Map<String,Object>>
  8 根据主键修改非空记录 
  9 根据指定sql语句更新 返回受影响行数 
 10 根据指定的id  删除
 11 根据指定的ids 删除
 12 根据指定实体  删除 

BaseDao  

package com.oracle.dao;

import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.oracle.annotation.ID;
import com.oracle.annotation.Table;
import com.oracle.util.ConnectionTool;
import com.oracle.util.SqlTool;



public class BaseDao {
	protected Connection conn;
	protected PreparedStatement ps;
	protected ResultSet rs;

	protected Connection getConnection() {
		return ConnectionTool.getConnection();
	}

	protected void close() {
		ConnectionTool.close(rs, ps, conn);
	}

	/**
	 * 插入一个记录
	 * 
	 * @param obj
	 */
	protected void insertObject(Object obj) {
		Class<?> clazz = obj.getClass();
		String sql = SqlTool.makeSql(clazz);
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sql);
			// 获得类的所有属性
			Field[] fs = clazz.getDeclaredFields();
			for (int i = 0; i < fs.length; i++) {
				fs[i].setAccessible(true);
				ps.setObject(i + 1, fs[i].get(obj));
			}
			System.out.println(ps);
			ps.executeUpdate();
		} catch (SQLException | IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查找全部
	 * 
	 * @param t
	 * @return List
	 */
	@SuppressWarnings("unchecked")
	protected <T> List<T> selectAll(T t) {
		List<T> list = new ArrayList<>();
		Class<?> clazz = t.getClass();
		String sql = "select * from " + clazz.getSimpleName();
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			Field[] fs = clazz.getDeclaredFields();
			while (rs.next()) {
				T tEntity = null;
				tEntity = (T) clazz.newInstance();// 为每条记录创建实体对象
				for (int i = 0; i < fs.length; i++) {// 遍历属性为了赋值
					fs[i].setAccessible(true);
					// System.out.println(fs[i].getType().getName()+"
					// "+fs[i].getName());
					// 这里有问题 Integer double date 。。。。
					if (fs[i].getType().getName().equals("java.lang.String")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getString(fs[i].getName()));
					} else if (fs[i].getType().equals(int.class)) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Integer")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Long")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getLong(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Double")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDouble(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.util.Date")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDate(fs[i].getName()));
					} else {
						fs[i].set(tEntity, rs.getObject(fs[i].getName()));
					}

				}
				System.out.println(tEntity);
				list.add(tEntity);
			}
		} catch (SQLException | InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 通过主键查找记录
	 * 
	 * @param obj
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected <T> T getObjectByID(T obj) {
		StringBuilder sb = new StringBuilder("select * from ");
		T t = null;
		Class<?> clazz = obj.getClass();
		Table table = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (table == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(table.value());// 根据注解值设置表名
		}
		// 获得所有属性 在里面找的有ID注解的属性
		Field[] fs = clazz.getDeclaredFields();
		Field id = null;
		for (int i = 0; i < fs.length; i++) {
			fs[i].setAccessible(true);
			if (fs[i].getDeclaredAnnotation(ID.class) != null) {
				id = fs[i];
				break;
			}
		}
		if (id == null) {
			id = fs[0];
		}
		sb.append("  where  " + id.getName() + " =  ?");
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sb.toString());
			ps.setObject(1, id.get(obj));
			System.out.println(ps);
			rs = ps.executeQuery();
			if (rs.next()) {
				t = (T) clazz.newInstance();
				for (int i = 0; i < fs.length; i++) {
					fs[i].setAccessible(true);
					if (fs[i].getType().getName().equals("java.lang.String")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getString(fs[i].getName()));
					} else if (fs[i].getType().equals(int.class)) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Integer")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Long")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getLong(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Double")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getDouble(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.util.Date")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getDate(fs[i].getName()));
					} else {
						fs[i].set(t, rs.getObject(fs[i].getName()));
					}
				}
			}
		} catch (SQLException | IllegalArgumentException | IllegalAccessException | InstantiationException e) {
			e.printStackTrace();
		}
		return t;
	}

	/**
	 * 给定ids主键查询
	 * 
	 * @param obj
	 * @param ids
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected <T> List<T> getObjectByIDs(T obj, int ids[]) {
		List<T> list = new ArrayList<>();
		StringBuilder sb = new StringBuilder("select * from ");
		T t = null;
		Class<?> clazz = obj.getClass();
		Table table = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (table == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(table.value());// 根据注解值设置表名
		}
		// 获得所有属性 在里面找的有ID注解的属性
		Field[] fs = clazz.getDeclaredFields();
		Field id = null;
		for (int i = 0; i < fs.length; i++) {
			fs[i].setAccessible(true);
			if (fs[i].getDeclaredAnnotation(ID.class) != null) {
				id = fs[i];
				break;
			}
		}
		if (id == null) {
			id = fs[0];
		}
		sb.append("  where  " + id.getName() + " in ");
		String s = "(";
		for (int a : ids) {
			s = s + a + ",";
		}
		s = s.substring(0, s.length() - 1) + ")";
		sb.append(s);
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sb.toString());
			rs = ps.executeQuery();
			while (rs.next()) {
				T tEntity = null;
				tEntity = (T) clazz.newInstance();// 为每条记录创建实体对象
				for (int i = 0; i < fs.length; i++) {// 遍历属性为了赋值
					fs[i].setAccessible(true);

					if (fs[i].getType().getName().equals("java.lang.String")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getString(fs[i].getName()));
					} else if (fs[i].getType().equals(int.class)) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Integer")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Long")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getLong(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Double")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDouble(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.util.Date")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDate(fs[i].getName()));
					} else {
						fs[i].set(tEntity, rs.getObject(fs[i].getName()));
					}

				}
				// System.out.println(tEntity);
				list.add(tEntity);
			}
		} catch (SQLException | InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}

		return list;

	}

	/**
	 * 通过给定非空字段查询
	 * 
	 * @param obj
	 * @param name
	 * @param value
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected <T> T getObjectByGiven(T obj, String name, Object value) {
		StringBuilder sb = new StringBuilder("select * from ");
		T t = null;
		Class<?> clazz = obj.getClass();
		Table table = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (table == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(table.value());// 根据注解值设置表名
		}
		Field[] fs = clazz.getDeclaredFields();
		sb.append("  where  " + name + " =  ?");
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sb.toString());
			ps.setObject(1, value);
			System.out.println(ps);
			rs = ps.executeQuery();
			if (rs.next()) {
				t = (T) clazz.newInstance();
				for (int i = 0; i < fs.length; i++) {
					fs[i].setAccessible(true);
					if (fs[i].getType().getName().equals("java.lang.String")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getString(fs[i].getName()));
					} else if (fs[i].getType().equals(int.class)) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Integer")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Long")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getLong(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Double")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getDouble(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.util.Date")) {
						// System.out.println(fs[i].getName());
						fs[i].set(t, rs.getDate(fs[i].getName()));
					} else {
						fs[i].set(t, rs.getObject(fs[i].getName()));
					}
				}
			}
		} catch (SQLException | IllegalArgumentException | IllegalAccessException | InstantiationException e) {
			e.printStackTrace();
		}
		return t;
	}

	/**
	 * 分页查询
	 * 
	 * @param obj
	 * @param pagesize
	 * @param pageOrder
	 * @return
	 */
	protected <T> List<T> getObjectForPage(T obj, int pagesize, int pageOrder) {
		List<T> list = new ArrayList<>();
		T t = null;
		Class<?> clazz = obj.getClass();
		String sql = "select * from " + clazz.getSimpleName() + " limit ?,?";
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, pagesize * (pageOrder - 1));
			ps.setInt(2, pagesize);
			rs = ps.executeQuery();
			Field[] fs = clazz.getDeclaredFields();
			while (rs.next()) {
				T tEntity = null;
				tEntity = (T) clazz.newInstance();// 为每条记录创建实体对象
				for (int i = 0; i < fs.length; i++) {// 遍历属性为了赋值
					fs[i].setAccessible(true);
					// System.out.println(fs[i].getType().getName()+"
					// "+fs[i].getName());
					// 这里有问题 Integer double date 。。。。
					if (fs[i].getType().getName().equals("java.lang.String")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getString(fs[i].getName()));
					} else if (fs[i].getType().equals(int.class)) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Integer")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getInt(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Long")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getLong(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.lang.Double")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDouble(fs[i].getName()));
					} else if (fs[i].getType().getName().equals("java.util.Date")) {
						// System.out.println(fs[i].getName());
						fs[i].set(tEntity, rs.getDate(fs[i].getName()));
					} else {
						fs[i].set(tEntity, rs.getObject(fs[i].getName()));
					}

				}
				// System.out.println(tEntity);
				list.add(tEntity);
			}
		} catch (SQLException | InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 根据sql语句查询 返回map
	 * 
	 * @param sql
	 * @return
	 */
	protected List<Map<String, Object>> selectBySql(String sql) {
		List<Map<String, Object>> list = new ArrayList<>();
		HashMap<String, Object> map = null;
		ResultSetMetaData data = null;
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sql);
			System.out.println(ps);
			rs = ps.executeQuery();
			data = rs.getMetaData();
			while (rs.next()) {
				map = new HashMap<>();
				for (int i = 1; i <= data.getColumnCount(); i++) {

					String c = data.getColumnName(i);
					Object v = rs.getObject(c);
					// System.out.println(c + ":" + v + "\t");
					map.put(c, v);
				}
				// System.out.println("===========");
				list.add(map);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 通过主键修改
	 * 
	 * @param obj
	 * @return
	 */
	protected <T> int updateById(T obj) {
		Class<?> clazz = obj.getClass();
		String sql = SqlTool.makeSqlUpdate(clazz);
		conn = this.getConnection();
		T t = this.getObjectByID(obj);
		// System.out.println(t);
		int flag = 0;
		try {
			ps = conn.prepareStatement(sql);
			// 获得类的所有属性
			Field[] fs = clazz.getDeclaredFields();
			Field id = null;
			int i;
			for (i = 0; i < fs.length; i++) {
				fs[i].setAccessible(true);
				if ((fs[i].getType().equals(int.class) && (int) fs[i].get(obj) != 0)
						|| (!fs[i].getType().equals(int.class) && fs[i].get(obj) != null)) {
					ps.setObject(i + 1, fs[i].get(obj));
				} else
					ps.setObject(i + 1, fs[i].get(t));
				if (fs[i].getDeclaredAnnotation(ID.class) != null) {
					id = fs[i];
				}
			}
			if (id == null) {
				id = fs[0];
			}
			ps.setObject(i + 1, id.get(obj));
			System.out.println(ps);
			flag = ps.executeUpdate();
		} catch (SQLException | IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 通过sql语句修改
	 * 
	 * @param obj
	 * @param sql
	 * @return
	 */
	protected <T> int updateBySql(T obj, String sql) {
		int flag = 0;
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sql);
			flag = ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 根据指定的id删除
	 * 
	 * @param obj
	 * @return
	 */
	protected <T> int deleteById(T obj) {
		int flag = 0;
		conn = this.getConnection();
		Class<?> clazz = obj.getClass();
		StringBuilder sql = new StringBuilder("delete from " + clazz.getSimpleName());
		Field[] fs = clazz.getDeclaredFields();
		Field id = null;
		for (int i = 0; i < fs.length; i++) {
			fs[i].setAccessible(true);
			if (fs[i].getDeclaredAnnotation(ID.class) != null) {
				id = fs[i];
				break;
			}
		}
		if (id == null) {
			id = fs[0];
		}
		sql.append("  where  " + id.getName() + " =? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setObject(1, id.get(obj));
			System.out.println(ps);
			flag = ps.executeUpdate();
		} catch (SQLException | IllegalArgumentException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 根据指定的ids删除
	 * @param obj
	 * @param ids
	 * @return
	 */
	protected <T> int deleteByIds(T obj, int[] ids) {
		int flag = 0;
		conn = this.getConnection();
		Class<?> clazz = obj.getClass();
		StringBuilder sql = new StringBuilder("delete from " + clazz.getSimpleName());
		Field[] fs = clazz.getDeclaredFields();
		Field id = null;
		for (int i = 0; i < fs.length; i++) {
			fs[i].setAccessible(true);
			if (fs[i].getDeclaredAnnotation(ID.class) != null) {
				id = fs[i];
				break;
			}
		}
		if (id == null) {
			id = fs[0];
		}
		sql.append("  where  " + id.getName() + " in");
		String s = "(";
		for (int a : ids) {
			s = s + a + ",";
		}
		s = s.substring(0, s.length() - 1) + ")";
		sql.append(s);
		try {
			ps = conn.prepareStatement(sql.toString());
			System.out.println(ps);
			flag = ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 根据给定字段删除
	 * @param obj
	 * @param name
	 * @param value
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected <T> int deleteByGiven(T obj, String name, Object value) {
		int flag=0;
		StringBuilder sb = new StringBuilder("delete from ");
		T t = null;
		Class<?> clazz = obj.getClass();
		Table table = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (table == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(table.value());// 根据注解值设置表名
		}
		Field[] fs = clazz.getDeclaredFields();
		sb.append("  where  " + name + " =  ?");
		conn = this.getConnection();
		try {
			ps = conn.prepareStatement(sb.toString());
			ps.setObject(1, value);
			System.out.println(ps);
			flag=ps.executeUpdate();
		} catch (SQLException | IllegalArgumentException e) {
			e.printStackTrace();
		}
		return flag;
	}
}

对反射赋值那一块的类型转换有点梗  写的乱七八糟的 暂时不想修改那个。。。


其中的声明:

//ID 作为主键

package com.oracle.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ID {
   
}


package com.oracle.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
      String value();
}


生成插入和更新的sql语句

package com.oracle.util;

import java.lang.reflect.Field;

import com.oracle.annotation.ID;
import com.oracle.annotation.Table;
import com.oracle.entity.Emp;

public class SqlTool {
	

	public static String makeSql(Class<?> clazz) {
		StringBuilder sb = new StringBuilder("insert into  ");
		sb.append(clazz.getSimpleName());
		sb.append("  (");
		Field[] fs = clazz.getDeclaredFields();
		for (int i = 0; i < fs.length; i++) {
			sb.append(fs[i].getName());
			if (i < fs.length - 1)
				sb.append(",");
		}
		sb.append(")");
		sb.append("  values (");
		for (int i = 0; i < fs.length; i++) {
			sb.append("?");
			if (i < fs.length - 1)
				sb.append(",");
		}
		sb.append(")");
		return sb.toString();
	}

	public static String makeSqlNew(Class<?> clazz) {
		StringBuilder sb = new StringBuilder("insert into  ");
		Table t = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (t == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(t.value());// 根据注解值设置表名
		}

		sb.append("  (");
		Field[] fs = clazz.getDeclaredFields();
		for (int i = 0; i < fs.length; i++) {
			sb.append(fs[i].getName());
			if (i < fs.length - 1)
				sb.append(",");
		}
		sb.append(")");
		sb.append("  values (");
		for (int i = 0; i < fs.length; i++) {
			sb.append("?");
			if (i < fs.length - 1)
				sb.append(",");
		}
		sb.append(")");
		return sb.toString();
	}

	public static String makeSqlUpdate(Class<?> clazz) {
		StringBuilder sb = new StringBuilder("update  ");
		Table t = clazz.getAnnotation(Table.class);// 根据注解类型获得注解
		if (t == null) {
			sb.append(clazz.getSimpleName());
		} else {
			sb.append(t.value());// 根据注解值设置表名
		}

		sb.append("  set ");
		Field[] fs = clazz.getDeclaredFields();
		
		for (int i = 0; i < fs.length; i++) {
			sb.append(fs[i].getName() + " =?");
			if (i < fs.length - 1)
				sb.append(",");
		}

		// 获得所有属性 在里面找的有ID注解的属性
		Field id = null;
		for (int i = 0; i < fs.length; i++) {
			fs[i].setAccessible(true);
			if (fs[i].getDeclaredAnnotation(ID.class) != null) {
				id = fs[i];
				break;
			}
		}
		if (id == null) {
			id = fs[0];
		}
		sb.append("  where  " + id.getName() + " =  ?");

		return sb.toString();
	}

	

}



测试entity


package com.oracle.entity;

import java.util.Date;

import com.oracle.annotation.ID;
import com.oracle.annotation.Table;

@Table("Emp")
public class Emp {
	  @ID
      private int empno;
      private String ename;
      private String job;
      private int mgr;
      private int sal;
      private Integer comm;
      private Date hiredate;
      private int deptno;
      
      
	public Emp(int empno, String ename, String job) {
		super();
		this.empno = empno;
		this.ename = ename;
		this.job = job;
	}
	
	
	
	public Emp(int empno) {
		super();
		this.empno = empno;
	}

	public Emp() {
		super();
	}

	private Emp(String job, int mgr, int sal) {
		super();
		this.job = job;
		this.mgr = mgr;
		this.sal = sal;
	}



	@Override
	public String toString() {
		return "Emp [empno=" + empno + ", ename=" + ename + ", job=" + job + ", mgr=" + mgr + ", sal=" + sal + ", comm="
				+ comm + ", hiredate=" + hiredate + ", deptno=" + deptno + "]";
	}



	public int getEmpno() {
		return empno;
	}
	public void setEmpno(int empno) {
		this.empno = empno;
	}
	public String getEname() {
		return ename;
	}
	public void setEname(String ename) {
		this.ename = ename;
	}
	public String getJob() {
		return job;
	}
	public void setJob(String job) {
		this.job = job;
	}
	public int getMgr() {
		return mgr;
	}
	public void setMgr(int mgr) {
		this.mgr = mgr;
	}
	public int getSal() {
		return sal;
	}
	public void setSal(int sal) {
		this.sal = sal;
	}
	public Integer getComm() {
		return comm;
	}
	public void setComm(Integer comm) {
		this.comm = comm;
	}
	public Date getHiredate() {
		return hiredate;
	}
	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}
	public int getDeptno() {
		return deptno;
	}
	public void setDeptno(int deptno) {
		this.deptno = deptno;
	}
	
      
}


EmpDao

package com.oracle.dao;

import java.util.List;

import com.oracle.entity.Emp;

public interface EmpDao {
	/**
	 * 插入记录
	 * @param emp
	 */
   public void addEmp(Emp emp);
   
   /**
    * 删除记录
    * @param emp
    */
   public void delete(Emp emp);
   
   /**
    * 查询所有信息
    * @return
    */
   public List<Emp> getEmps();
   
   public Emp getEmpById(Emp emp);
}
Impl
package com.oracle.daoImpl;

import java.util.List;

import com.oracle.dao.BaseDao;
import com.oracle.dao.EmpDao;
import com.oracle.entity.Emp;

public class EmpDaoImpl extends BaseDao implements EmpDao {
	@Override
	public void addEmp(Emp emp) {
     		this.insertObject(emp);
	}
	
	

	@Override
	public List<Emp> getEmps() {
		return this.selectAll(new Emp());
	}



	@Override
	public void delete(Emp emp) {
		this.delete(emp);
		
	}
	

	@Override
	public Emp getEmpById(Emp emp) {
		
		return this.getObjectByID(emp);
	}

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值