1 36 37 package com.bluecubs.xinco.core.server; 38 39 import java.util.Vector ; 40 import java.sql.*; 41 42 import com.bluecubs.xinco.core.*; 43 44 public class XincoCoreGroupServer extends XincoCoreGroup { 45 46 public XincoCoreGroupServer(int attrID, XincoDBManager DBM) throws XincoException { 48 49 try { 50 51 Statement stmt = DBM.con.createStatement(); 52 ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_group WHERE id=" + attrID); 53 54 int RowCount = 0; 56 while (rs.next()) { 57 RowCount++; 58 setId(rs.getInt("id")); 59 setDesignation(rs.getString("designation")); 60 setStatus_number(rs.getInt("status_number")); 61 } 62 if (RowCount < 1) { 63 throw new XincoException(); 64 } 65 66 stmt.close(); 67 68 } catch (Exception e) { 69 throw new XincoException(); 70 } 71 72 } 73 74 public XincoCoreGroupServer(int attrID, String attrD, int attrSN) throws XincoException { 76 77 setId(attrID); 78 setDesignation(attrD); 79 setStatus_number(attrSN); 80 81 } 82 83 public int write2DB(XincoDBManager DBM) throws XincoException{ 85 86 try { 87 88 Statement stmt; 89 90 if (getId() > 0) { 91 stmt = DBM.con.createStatement(); 92 stmt.executeUpdate("UPDATE xinco_core_group SET designation='" + getDesignation().replaceAll("'","\\\\'") + "', status_number=" + getStatus_number() + " WHERE id=" + getId()); 93 stmt.close(); 94 } else { 95 setId(DBM.getNewID("xinco_core_group")); 96 97 stmt = DBM.con.createStatement(); 98 stmt.executeUpdate("INSERT INTO xinco_core_group VALUES (" + getId() + ", '" + getDesignation().replaceAll("'","\\\\'") + "', " + getStatus_number() + ")"); 99 stmt.close(); 100 } 101 102 DBM.con.commit(); 103 104 } catch (Exception e) { 105 try { 106 DBM.con.rollback(); 107 } catch (Exception erollback) { 108 } 109 throw new XincoException(); 110 } 111 112 return getId(); 113 114 } 115 116 public static Vector getXincoCoreGroups(XincoDBManager DBM) { 118 119 Vector coreGroups = new Vector (); 120 121 try { 122 123 Statement stmt = DBM.con.createStatement(); 124 ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_group ORDER BY designation"); 125 126 while (rs.next()) { 127 coreGroups.addElement(new XincoCoreGroupServer(rs.getInt("id"), rs.getString("designation"), rs.getInt("status_number"))); 128 } 129 130 stmt.close(); 131 132 } catch (Exception e) { 133 coreGroups.removeAllElements(); 134 } 135 136 return coreGroups; 137 } 138 139 } 140 | Popular Tags |