开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2015-01-14
详细说明:
package com.neusoft.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.neusoft.entity.Group; import com.neusoft.entity.Person; import com.neusoft.util.DbUtil; public class PersonTableDao { public static final String SQL1= "insert into Person_Table"+" (p_id,g_name,p_name,p_birthday,p_phone,p_Email,p_address)"+" values(?,?,?,?,?,?,?)"; public static final String SQL2= "update Person_Table set p_id=?,g_name=?,p_birthday=to_date(?,'dd-mm-yyyy'),p_phone=?,p_Email=?,p_address=? where p_name=?"; public static final String SQL3= "delete from Person_Table where p_name=?"; public static final String SQL4= "select * from Person_Table"; public static final String SQL5= "select * from Person_Table where p_name = ?"; public boolean addPerson(Person person){ Connection conn = null; PreparedStatement stmt = null; conn = DbUtil.getConn(); try { stmt = conn.prepareStatement(SQL1); //向Person_Table中插入数据 stmt.setInt(1,person.getP_id()); stmt.setString(2,person.getG_name()); stmt.setString(3,person.getP_name()); stmt.setDate(4,new java.sql.Date(person.getP_birthday().getTime())); stmt.setString(5,person.getP_phone()); stmt.setString(6,person.getP_Email()); stmt.setString(7,person.getP_address()); int rows = stmt.executeUpdate(); if(rows>0) return true; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); }finally{ DbUtil.getClose(conn, stmt); } return false; } public boolean updatePersonMessage(Person person){ Connection conn = null; PreparedStatement stmt = null; conn = DbUtil.getConn(); try { stmt = conn.prepareStatement(SQL2);//根据p_name更新person表中的数据。 stmt.setInt(1,person.getP_id()); stmt.setString(2,person.getG_name()); stmt.setDate(3,new java.sql.Date(person.getP_birthday().getTime())); stmt.setString(4,person.getP_phone()); stmt.setString(5,person.getP_Email()); stmt.setString(6,person.getP_address()); stmt.setString(7,person.getG_name()); int rows = stmt.executeUpdate(); if(rows>0) return true; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); }finally{ DbUtil.getClose(conn, stmt); } return false; } public boolean deletePersonMessage(String p_name){ Connection conn = null; PreparedStatement stmt = null; conn = DbUtil.getConn(); try { stmt = conn.prepareStatement(SQL3);//根据p_name删除person表中对应的数据。 stmt.setString(1,p_name); int rows = stmt.executeUpdate(); if(rows>0) return true; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); }finally{ DbUtil.getClose(conn, stmt); } return false; } public List getAllPersonMessage(){ //当p_name没有输入时调用该方法。 Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; conn=DbUtil.getConn(); List list = new ArrayList(); try { stmt = conn.prepareStatement(SQL4); rs = stmt.executeQuery(); while (rs.next()) { Person person = new Person(); person.setP_id(rs.getInt("p_id")); person.setG_name(rs.getString("g_name")); person.setP_name(rs.getString("p_name")); person.setP_birthday(rs.getDate("p_birthday")); person.setP_phone(rs.getString("p_phone")); person.setP_Email(rs.getString("p_Email")); person.setP_address(rs.getString("p_address")); list.add(person); } System.out.println(list.size()); return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); return null; }finally{ DbUtil.getClose(conn, stmt,rs); } } public List getPersonMessageByName(String p_name){ //根据联系人名称查询相关的数据。 Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; conn=DbUtil.getConn(); List list = new ArrayList(); try { stmt = conn.prepareStatement(SQL5); stmt.setString(1,p_name); rs = stmt.executeQuery(); while (rs.next()) { Person person = new Person(); person.setP_id(rs.getInt("p_id")); person.setG_name(rs.getString("g_name")); person.setP_name(rs.getString("p_name")); person.setP_birthday(rs.getDate("p_birthday")); person.setP_phone(rs.getString("p_phone")); person.setP_Email(rs.getString("p_Email")); person.setP_address(rs.getString("p_address")); list.add(person); } System.out.println(list.size()); return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); return null; }finally{ DbUtil.getClose(conn, stmt,rs); } } public static void main(String[] args) { new PersonTableDao().deletePersonMessage("陈其鸣"); System.out.println("刪除成功"); /*Group g= new Group(); g.setG_id(10006); g.setG_name("好友"); g.setG_desc("good friend"); new GroupTableDao().addGroup(g); System.out.println("添加成功");*/ /* List list = new PersonTableDao().getAllPersonMessage(); System.out.println(list.size());*/ /* List list = new PersonTableDao().getPersonMessageByName("陈其鸣"); System.out.println(list.size());*/ } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.