Example #1
0
 public static void addConnPool(ZCDatabaseSchema db) {
   DBConnConfig dcc = new DBConnConfig();
   dcc.DBName = db.getDBName();
   dcc.DBPassword = db.getPassword();
   dcc.DBPort = (int) db.getPort();
   dcc.DBServerAddress = db.getAddress();
   dcc.DBType = db.getServerType();
   dcc.DBUserName = db.getUserName();
   dcc.PoolName = ("_OuterDatabase_" + db.getID());
   dcc.TestTable = db.getTestTable();
   dcc.isLatin1Charset = "Y".equals(db.getLatin1Flag());
   if (!DBConnPool.getPoolMap().containsKey(dcc.PoolName + ".")) new DBConnPoolImpl(dcc);
 }
Example #2
0
 public void connTest() {
   DBConnConfig dcc = new DBConnConfig();
   dcc.DBName = $V("DBName");
   dcc.DBPassword = $V("Password");
   dcc.DBPort = Integer.parseInt($V("Port"));
   dcc.DBServerAddress = $V("Address");
   dcc.DBType = $V("ServerType");
   dcc.DBUserName = $V("UserName");
   dcc.isLatin1Charset = "Y".equals($V("Latin1Flag"));
   DBConn conn = null;
   try {
     conn = DBConnPoolImpl.createConnection(dcc, false);
     String msg = "测试连接成功";
     DataAccess da = new DataAccess(conn);
     try {
       da.executeOneValue(new QueryBuilder("select 1 from " + $V("TestTable") + " where 1=2"));
     } catch (Exception e) {
       e.printStackTrace();
       msg = msg + ",但表" + $V("TestTable") + "不存在!";
     } finally {
       da.close();
     }
     this.Response.setMessage(msg);
     return;
   } catch (Exception e) {
     e.printStackTrace();
     this.Response.setError("连接到数据库时发生错误:" + e.getMessage());
     return;
   } finally {
     if (conn != null)
       try {
         conn.closeReally();
       } catch (SQLException e) {
         e.printStackTrace();
       }
   }
 }