1 36 37 package com.bluecubs.xinco.core.server; 38 39 import java.sql.*; 40 import javax.sql.DataSource ; 41 import javax.naming.InitialContext ; 42 import com.bluecubs.xinco.conf.XincoConfigSingletonServer; 43 44 public class XincoDBManager { 45 46 public Connection con; 47 public XincoConfigSingletonServer config; 48 public static int count = 0; 49 50 public XincoDBManager() throws Exception { 51 52 config = XincoConfigSingletonServer.getInstance(); 54 DataSource datasource = (DataSource )(new InitialContext ()).lookup(config.JNDIDB); 55 con = datasource.getConnection(); 56 con.setAutoCommit(false); 57 count++; 58 } 59 60 public int getNewID(String attrTN) throws Exception { 61 62 int newID = 0; 63 Statement stmt; 64 65 stmt = con.createStatement(); 66 ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_id WHERE tablename='" + attrTN + "'"); 67 while (rs.next()) { 68 newID = rs.getInt("last_id") + 1; 69 } 70 stmt.close(); 71 72 stmt = con.createStatement(); 73 stmt.executeUpdate("UPDATE xinco_id SET last_id=last_id+1 WHERE tablename='" + attrTN + "'"); 74 stmt.close(); 75 76 return newID; 77 78 } 79 80 protected void finalize() throws Throwable { 81 try { 82 count--; 83 con.close(); 84 } finally { 85 if (!con.isClosed()) { 86 count++; 87 } 88 super.finalize(); 89 } 90 } 91 92 } 93 | Popular Tags |