package DB; import java.sql.Connection; import java.sql.DriverManager; import Bean.*; import java.util.ArrayList; import java.sql.PreparedStatement; import java.sql.ResultSet; public class DBConnect { public DBConnect() { } public Connection getCon() { Connection con = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:test"); } catch (Exception ex) { ex.printStackTrace(); } return con; } //用户操作 public ArrayList getUsers() { //得到所有用户 ArrayList ar = new ArrayList(); PreparedStatement ps = null; Connection con = null; ResultSet rs = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_UserDis}"); rs = ps.executeQuery(); userBean users = null; while (rs.next()) { users = new userBean(); users.setUserId(rs.getInt(1)); users.setUserName(rs.getString(2)); users.setPassWord(rs.getString(3)); users.setClassMessage(rs.getString(4)); ar.add(users); } } catch (Exception ex) { ex.printStackTrace(); } return ar; } public int deleteUsers(int userId) { //删除用户 int i = 5; Connection con = null; PreparedStatement ps = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_deleteUsers(?)}"); ps.setInt(1, userId); i = ps.executeUpdate(); } catch (Exception ex) { ex.printStackTrace(); } return i; } public int addUsers(String username, String psd) { //增加用户 Connection con = null; PreparedStatement ps = null; int i = 5; try { con = this.getCon(); ps = con.prepareCall("{call proc_AddUser(?,?)}"); ps.setString(1, username); ps.setString(2, psd); i = ps.executeUpdate(); } catch (Exception ex) { ex.printStackTrace(); } return i; } //宠物主人操作 public ArrayList getOwners() { //查询所有主人 Connection con = null; PreparedStatement ps = null; ResultSet rs = null; ArrayList ar = new ArrayList(); try { OwnersBean owners = null; con = this.getCon(); ps = con.prepareCall("{call proc_OwnerDis}"); rs = ps.executeQuery(); while (rs.next()) { owners = new OwnersBean(); owners.setOwnerId(rs.getInt(1)); owners.setOwnerName(rs.getString(2)); owners.setOwnerPhone(rs.getString(3)); owners.setOwnerImage(rs.getString(4)); ar.add(owners); } } catch (Exception ex) { ex.printStackTrace(); } return ar; } public ArrayList getOwnersByName(String ownername) { //按姓名查询主人 Connection con = null; PreparedStatement ps = null; ResultSet rs = null; ArrayList ar = new ArrayList(); try { OwnersBean owners = null; con = this.getCon(); ps = con.prepareCall("{call proc_OwnerDis(?)}"); ps.setString(1, ownername); rs = ps.executeQuery(); while (rs.next()) { owners = new OwnersBean(); owners.setOwnerId(rs.getInt(1)); owners.setOwnerName(rs.getString(2)); owners.setOwnerPhone(rs.getString(3)); owners.setOwnerImage(rs.getString(4)); ar.add(owners); } } catch (Exception ex) { ex.printStackTrace(); } return ar; } public OwnersBean getOwnersById(int ownerId) { //按id查询主人 Connection con = null; PreparedStatement ps = null; ResultSet rs = null; ArrayList ar = new ArrayList(); OwnersBean owners = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_OwnerById(?)}"); ps.setInt(1, ownerId); rs = ps.executeQuery(); while (rs.next()) { owners = new OwnersBean(); owners.setOwnerId(rs.getInt(1)); owners.setOwnerName(rs.getString(2)); owners.setOwnerPhone(rs.getString(3)); owners.setOwnerImage(rs.getString(4)); } } catch (Exception ex) { ex.printStackTrace(); } return owners; } public int addOwners(String ownername, String ownerphone, String ownerimage) { //增加主人 int i = 5; Connection con = null; PreparedStatement ps = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_AddOwner(?,?,?)}"); ps.setString(1, ownername); ps.setString(2, ownerphone); ps.setString(3, ownerimage); i = ps.executeUpdate(); } catch (Exception ex) { } return i; } public int updateOwners(int ownerId, String ownerphone,String ownerimage) throws Exception { //修改主人 int i = 5; Connection con = null; PreparedStatement ps = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_UpdateOwner(?,?,?)}"); ps.setInt(1, ownerId); ps.setString(2, ownerphone); ps.setString(3,ownerimage); i = ps.executeUpdate(); } catch (Exception ex) { throw ex; } return i; } public int deleteOwners(int ownerId) { //删除主人 int i = 5; Connection con = null; PreparedStatement ps = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_DeleteOwner(?)}"); ps.setInt(1, ownerId); i = ps.executeUpdate(); } catch (Exception ex) { ex.printStackTrace(); } return i; } //宠物类别操作 public ArrayList getType() { //得到所有宠物类别 ArrayList ar = new ArrayList(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; petTypeBean type = null; try { con = this.getCon(); ps = con.prepareCall("{call proc_TypeDis}"); rs = ps.executeQuery(); while (rs.next()) { type = new petTypeBean(); type.setTypeId(rs.getInt(1)); type.setTypeName(rs.getString(2)); type.setTypeMessage(rs.getString(3)); ar.add(type); } } catch (Exception ex) { ex.printStackTrace(); } return ar; } public petTypeBean getTypeById(int typeid) { //按编号得到宠物类别 // ArrayList ar = new ArrayList(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; petTypeBean type = new petTypeBean(); try { con = this.getCon(); ps = con.prepareCall("{call proc_TypeById(?)}"); ps.setInt(1,typeid); rs = ps.executeQuery(); if (rs.next()) { type = new petTypeBean(); type.setTypeId(rs.getInt(1)); type.setTypeName(rs.getString(2)); type.setTypeMessage(rs.getString(3)); } } catch (Exception ex) { ex.printStackTrace();
相关知识
云农宠物博客宠物诊所电话,云农宠物博客宠物诊所电话多少
【旺佳宠物诊所】旺佳宠物诊所电话,旺佳宠物诊所地址
【建新宠物诊所】建新宠物诊所电话,建新宠物诊所地址
开个宠物诊所大概需要多少钱?【宠物医院吧】
宠物诊所和宠物医院的区别 宠物医院和宠物诊所哪个好
兽医诊所行业云计算与大数据应用.docx
宠物诊所与宠物医院有什么区别!
宠物诊所与宠物医院有什么区别!
宠物诊所和宠物医院的区别
【爱迪宠物诊所】爱迪宠物诊所电话,爱迪宠物诊所地址
网址: 云飞宠物诊所宠物医院 https://m.mcbbbk.com/newsview384377.html
上一篇: 宠物系统JSP项目资源 |
下一篇: 求樱花庄的宠物女孩百度云盘资源 |