个人信息助理系统

时间:2018-02-03 16:43:40
【文件属性】:

文件名称:个人信息助理系统

文件大小:2.18MB

文件格式:ZIP

更新时间:2018-02-03 16:43:40

系统

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());*/ } }


网友评论