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

📄 persondaoimpl.java

📁 Spring2.0宝典
💻 JAVA
字号:
package lee;

import java.sql.Statement;
import java.sql.ResultSet;
import java.util.List;
import java.util.ArrayList;
/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class PersonDaoImpl implements PersonDao
{
	private Statement stmt;
	private DBConn dc;
	public PersonDaoImpl()
	{
		dc = DBConn.instance();
	}
	public void createPerson(PersonBean p)throws Exception
	{
		stmt = dc.openStmt();
		stmt.execute("insert into person_test(p_name,p_age) values('" + p.getName() + "'," + p.getAge()+")");
	}
	public PersonBean getPerson(int id) throws Exception
	{
		stmt = dc.openStmt();
		ResultSet rs = stmt.executeQuery("select * from person_test where p_id = " + id);
		return new PersonBean(rs.getString("p_name"),rs.getInt("p_age"));
	}
	public List findPersonsByName(String name) throws Exception
	{
		stmt = dc.openStmt();
		String sql = "select * from person_test where p_name like '%" + name + "%'";
		ResultSet rs = stmt.executeQuery(sql);
		List result = new ArrayList();
		while (rs.next())
		{
			result.add(new PersonBean(rs.getString("p_name"),rs.getInt("p_age")));
		}
		return result;
	}
	public void deletePerson(int id) throws Exception
	{
		stmt = dc.openStmt();
		stmt.execute("delete from person_test where p_id = " + id);
	}
	public void deletePersonsByAge(int startAge , int EndAge) throws Exception
	{
		stmt = dc.openStmt();
		stmt.execute("delete from person_test where p_age between " + startAge + " and " + EndAge);
	}
	public void updatePerson(PersonBean pb)throws Exception
	{
		stmt = dc.openStmt();
		stmt.execute("update person_test set p_name = '" + pb.getName() +  "' , p_age=" + pb.getAge() + " where p_id =" + pb.getId());
	}
}

⌨️ 快捷键说明

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