Пример #1
0
  public int delete(ValueObject obj) throws SQLException {

    if ((obj instanceof PT_KICA_ERR_LOGEntity) == false) {
      throw new SQLException("DAO 에러(1): PT_KICA_ERR_LOG : delete() ");
    }
    PT_KICA_ERR_LOGEntity entity = (PT_KICA_ERR_LOGEntity) obj;

    Connection conn = null;
    PreparedStatement ps = null;
    int result = 0;

    StringBuffer sb = new StringBuffer();
    sb.append("delete from PT_KICA_ERR_LOG  where  1=1")
        .append(" and SEQ = ")
        .append(toDB(entity.getSEQ()));

    KJFLog.sql(sb.toString());

    try {

      conn = this.getConnection();
      ps = conn.prepareStatement(sb.toString());

      result = ps.executeUpdate();

    } catch (SQLException e) {
      throw e;
    } finally {
      if (ps != null) ps.close();
      this.release(conn);
    }

    return result;
  }
Пример #2
0
  public int update(ValueObject obj) throws SQLException {

    if ((obj instanceof PT_KICA_ERR_LOGEntity) == false) {
      throw new SQLException("DAO 에러(1): PT_KICA_ERR_LOG : update() ");
    }
    PT_KICA_ERR_LOGEntity entity = (PT_KICA_ERR_LOGEntity) obj;

    Connection conn = null;
    PreparedStatement ps = null;
    int result = 0;

    StringBuffer sb = new StringBuffer();
    sb.append("update PT_KICA_ERR_LOG  set ")
        .append("U_D_FLAG = ")
        .append(toDB(entity.getU_D_FLAG()))
        .append(",")
        .append("YYYYMMDD = ")
        .append(toDB(entity.getYYYYMMDD()))
        .append(",")
        .append("TRANSHOUR = ")
        .append(toDB(entity.getTRANSHOUR()))
        .append(",")
        .append("FILENAME = ")
        .append(toDB(entity.getFILENAME()))
        .append(",")
        .append("ERRLOG = ")
        .append(toDB(entity.getERRLOG()))
        .append(",")
        .append("RESULT_FLAG = ")
        .append(toDB(entity.getRESULT_FLAG()))
        .append(",")
        .append("UPD_DT = ")
        .append(toDB(entity.getUPD_DT()))
        .append(",")
        .append("INS_DT = ")
        .append(toDB(entity.getINS_DT()))
        .append(" where  1=1 ");

    sb.append(" and SEQ = ").append(toDB(entity.getSEQ()));

    KJFLog.sql(sb.toString());

    try {

      conn = this.getConnection();
      ps = conn.prepareStatement(sb.toString());

      int i = 1;

      result = ps.executeUpdate();

    } catch (SQLException e) {
      throw e;
    } finally {
      if (ps != null) ps.close();
      this.release(conn);
    }

    return result;
  }
Пример #3
0
  public String insertSql(ValueObject obj) throws SQLException {

    if ((obj instanceof PT_KICA_ERR_LOGEntity) == false) {
      throw new SQLException("DAO 에러(1): PT_KICA_ERR_LOG : insert() ");
    }
    PT_KICA_ERR_LOGEntity entity = (PT_KICA_ERR_LOGEntity) obj;

    StringBuffer sb = new StringBuffer();
    sb.append("insert into PT_KICA_ERR_LOG ")
        .append(" ( SEQ,U_D_FLAG,YYYYMMDD,TRANSHOUR,FILENAME,ERRLOG,RESULT_FLAG,UPD_DT,INS_DT ) ")
        .append(" values ( ")
        .append(toDB(entity.getSEQ()))
        .append(",")
        .append(toDB(entity.getU_D_FLAG()))
        .append(",")
        .append(toDB(entity.getYYYYMMDD()))
        .append(",")
        .append(toDB(entity.getTRANSHOUR()))
        .append(",")
        .append(toDB(entity.getFILENAME()))
        .append(",")
        .append(toDB(entity.getERRLOG()))
        .append(",")
        .append(toDB(entity.getRESULT_FLAG()))
        .append(",")
        .append(toDB(entity.getUPD_DT()))
        .append(",")
        .append(toDB(entity.getINS_DT()))
        .append(" ) ");

    return sb.toString();
  }
Пример #4
0
  /**
   * Execute Task locally and wait
   *
   * @param cmd command
   * @return execution info
   */
  public String executeLocal(String cmd) {
    log.config(cmd);
    if (m_task != null && m_task.isAlive()) m_task.interrupt();

    m_task = new Task(cmd);
    m_task.start();

    StringBuffer sb = new StringBuffer();
    while (true) {
      //  Give it a bit of time
      try {
        Thread.sleep(500);
      } catch (InterruptedException ioe) {
        log.log(Level.SEVERE, cmd, ioe);
      }
      //  Info to user
      sb.append(m_task.getOut())
          .append("\n-----------\n")
          .append(m_task.getErr())
          .append("\n-----------");

      //  Are we done?
      if (!m_task.isAlive()) break;
    }
    log.config("done");
    return sb.toString();
  } //	executeLocal
Пример #5
0
  public List<ClientEventEntry> findLogEvents(
      List<SearchConstraint> constraints, List<String> orderBy, int offset, int limit, Connection c)
      throws SQLException {
    StringBuffer sql =
        new StringBuffer(
            "select e.event_id, e.customer_id, e.user_id, e.event_time, e.description, e.has_log_file from dat_client_log_events e ");
    appendWhere(sql, constraints, s_propToColumnMap);
    appendOrderBy(sql, orderBy, "e.event_id desc", s_propToColumnMap);
    appendLimits(sql, offset, limit);

    Statement stmt = null;
    ResultSet rs = null;
    try {
      stmt = c.createStatement();
      rs = stmt.executeQuery(sql.toString());
      List<ClientEventEntry> results = new ArrayList<ClientEventEntry>();
      while (rs.next()) {
        ClientEventEntry entry =
            new ClientEventEntry(
                rs.getInt(1),
                rs.getInt(2),
                rs.getInt(3),
                resolveDate(rs.getTimestamp(4)),
                rs.getString(5),
                rs.getInt(6) != 0);
        results.add(entry);
      }
      return results;
    } finally {
      DbUtils.safeClose(rs);
      DbUtils.safeClose(stmt);
    }
  }
  private String buildMultipleSelectString(ReportParameter reportParameter, Object[] values) {
    StringBuffer sb = new StringBuffer();

    if (values == null || values.length < 1 || values[0].equals("")) return "";

    for (int j = 0; j < values.length; j++) {
      String value = "";

      if (values[j] instanceof ReportParameterValue) {
        value = ((ReportParameterValue) values[j]).getId().toString();
      } else {
        value = (String) values[j];
      }

      if (j > 0) {
        sb.append(',');
      }

      if (reportParameter.getClassName().equals("java.lang.String")) {
        sb.append("'" + value + "'");
      } else {
        sb.append(value);
      }
    }

    return sb.toString();
  }
  /**
   * 領域の一覧(コンポボックス用)を取得する。
   *
   * @param connection コネクション
   * @return 事業情報
   * @throws ApplicationException
   */
  public static List selectRyouikiKubunInfoList(Connection connection)
      throws ApplicationException, NoDataFoundException {

    // -----------------------
    // SQL文の作成
    // -----------------------
    String select =
        "SELECT"
            + " A.RYOIKI_NO"
            + ",A.RYOIKI_RYAKU"
            + " FROM MASTER_RYOIKI A"
            + " ORDER BY RYOIKI_NO";
    StringBuffer query = new StringBuffer(select);

    if (log.isDebugEnabled()) {
      log.debug("query:" + query);
    }

    // -----------------------
    // リスト取得
    // -----------------------
    try {
      return SelectUtil.select(connection, query.toString());
    } catch (DataAccessException e) {
      throw new ApplicationException("領域情報検索中にDBエラーが発生しました。", new ErrorInfo("errors.4004"), e);
    } catch (NoDataFoundException e) {
      throw new NoDataFoundException("領域マスタに1件もデータがありません。", e);
    }
  }
Пример #8
0
 public Connection connect(String url, Properties info) throws SQLException {
   if (ConnectionLogger.isInfoEnabled()) {
     StringBuffer sb = new StringBuffer();
     sb.append("connect to URL ").append(url).append(" with properties: ").append(info.toString());
     ConnectionLogger.info(sb.toString());
   }
   if (!acceptsURL(url)) throw new SQLException("Invalid URL" + url);
   url = "jdbc:" + url.substring(urlPrefix.length());
   StringTokenizer ts = new StringTokenizer(url, ":/;=&?", false);
   String targetDriver = null;
   while (ts.hasMoreTokens()) {
     String s = ts.nextToken();
     logger.debug("s = " + s);
     if (targetDriverParameter.equals(s) && ts.hasMoreTokens()) {
       targetDriver = ts.nextToken();
       break;
     }
   }
   if (targetDriver == null)
     throw new SQLException("Can't find targetDriver parameter in URL: " + url);
   url =
       url.substring(0, url.length() - targetDriver.length() - targetDriverParameter.length() - 2);
   try {
     Class.forName(targetDriver);
     return ConnectionLoggingProxy.wrap(DriverManager.getConnection(url, info));
   } catch (Exception e) {
     ConnectionLogger.error(e.getMessage(), e);
     throw new SQLException(e.getMessage());
   }
 }
 private void revokeDelegatedPrivilege(Connection dConn, Connection gConn, String tableName) {
   int num = SQLTest.random.nextInt(SQLTest.numOfWorkers) + 1;
   ArrayList<SQLException> exceptionList = new ArrayList<SQLException>();
   String grantees = getGrantees(num);
   StringBuffer sql = new StringBuffer();
   int whichPriv = SQLTest.random.nextInt(tablePriv.length);
   sql.append("revoke " + tablePriv[whichPriv] + " on " + tableName + " from " + grantees);
   Log.getLogWriter().info("security statement is " + sql.toString());
   try {
     Statement stmt = dConn.createStatement();
     stmt.execute(sql.toString()); // execute authorization
     dConn.commit();
     stmt.close();
   } catch (SQLException se) {
     SQLHelper.handleDerbySQLException(se, exceptionList);
   }
   try {
     Statement stmt = gConn.createStatement();
     stmt.execute(sql.toString()); // execute authorization
     gConn.commit();
     stmt.close();
   } catch (SQLException se) {
     SQLHelper.handleGFGFXDException(se, exceptionList);
   }
 }
Пример #10
0
 public GenericVO findByPK(GenericVO vo) throws AppException, SysException {
   ProvinceSVO result = null;
   ProvinceSVO province = (ProvinceSVO) vo;
   StringBuffer sql = new StringBuffer("select");
   sql.append(" a.PROV_ID,a.NAME");
   sql.append(" from PROVINCE a where 1=1");
   sql.append(" and PROV_ID=?");
   Connection connection = null;
   PreparedStatement ps = null;
   ResultSet rs = null;
   try {
     connection = ConnectionFactory.getConnection();
     ps = connection.prepareStatement(sql.toString());
     ps.setString(1, province.getProvId());
     rs = ps.executeQuery();
     result = (ProvinceSVO) ResultSetUtil.convertToVo(rs, ProvinceSVO.class);
   } catch (SQLException e) {
     throw new SysException("", "findByPK error..", e);
   } finally {
     try {
       if (rs != null) {
         rs.close();
       }
       if (ps != null) {
         ps.close();
       }
     } catch (SQLException e) {
     }
   }
   return result;
 }
Пример #11
0
 private String createBlanks(int count) {
   StringBuffer strBuf = new StringBuffer();
   for (int i = 0; i < count; i++) {
     strBuf.append("   ");
   }
   return strBuf.toString();
 }
Пример #12
0
 /**
  * ************************************************************************ Lineas de Remesa
  *
  * @param whereClause where clause or null (starting with AND)
  * @return lines
  */
 public MRemesaLine[] getLines(String whereClause, String orderClause) {
   ArrayList list = new ArrayList();
   StringBuffer sql = new StringBuffer("SELECT * FROM C_RemesaLine WHERE C_Remesa_ID=? ");
   if (whereClause != null) sql.append(whereClause);
   if (orderClause != null) sql.append(" ").append(orderClause);
   PreparedStatement pstmt = null;
   try {
     pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
     pstmt.setInt(1, getC_Remesa_ID());
     ResultSet rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MRemesaLine(getCtx(), rs));
     rs.close();
     pstmt.close();
     pstmt = null;
   } catch (Exception e) {
     log.saveError("getLines - " + sql, e);
   } finally {
     try {
       if (pstmt != null) pstmt.close();
     } catch (Exception e) {
     }
     pstmt = null;
   }
   //
   MRemesaLine[] lines = new MRemesaLine[list.size()];
   list.toArray(lines);
   return lines;
 } //	getLines
Пример #13
0
 @Override
 public void deleteUser(User user) throws Exception {
   StringBuffer sqlStmt = new StringBuffer();
   sqlStmt.append("DELETE FROM ").append(usersTable);
   sqlStmt.append(" WHERE username='******'");
   doUpdate(sqlStmt.toString());
 }
Пример #14
0
 public void add(GenericVO vo) throws AppException, SysException {
   StaffWorkAreaSVO staffWorkArea = (StaffWorkAreaSVO) vo;
   StringBuffer sql = new StringBuffer("insert into");
   sql.append(
       " STAFF_WORK_AREA(STAFF_WORK_AREA_ID,STAFF_ID,WORK_AREA_ID,GRANTOR,ADMIN_FLAG,STS,STS_DATE,CREATE_DATE) values(?,?,?,?,?,?,?,?)");
   Connection connection = null;
   PreparedStatement ps = null;
   try {
     connection = ConnectionFactory.getConnection();
     ps = connection.prepareStatement(sql.toString());
     ps.setString(1, staffWorkArea.getStaffWorkAreaId());
     ps.setString(2, staffWorkArea.getStaffId());
     ps.setString(3, staffWorkArea.getWorkAreaId());
     ps.setString(4, staffWorkArea.getGrantor());
     ps.setString(5, staffWorkArea.getAdminFlag());
     ps.setString(6, staffWorkArea.getSts());
     ps.setDate(7, staffWorkArea.getStsDate());
     ps.setDate(8, staffWorkArea.getCreateDate());
     ps.execute();
     connection.commit();
   } catch (SQLException e) {
     throw new SysException("", "add error..", e);
   } finally {
     try {
       if (ps != null) {
         ps.close();
       }
     } catch (SQLException e) {
     }
   }
 }
Пример #15
0
  /**
   * Remove password & trusted token and log all other properties
   *
   * @param connUrl - URL used to connect to server
   * @param info - properties object supplied
   */
  private void logConnectionProperties(String connUrl, Properties info) {
    StringBuffer modifiedUrl = new StringBuffer();

    // If we have valid URL
    if (connUrl != null) {
      // We need wipe out the password here, before we write to the log
      int startIndex = connUrl.indexOf("password="******"password=***"); // $NON-NLS-1$
        int endIndex = connUrl.indexOf(";", startIndex + 9); // $NON-NLS-1$
        if (endIndex != -1) {
          modifiedUrl.append(";").append(connUrl.substring(endIndex)); // $NON-NLS-1$
        }
      }
      logger.fine("Connection Url=" + modifiedUrl); // $NON-NLS-1$
    }

    // Now clone the properties object and remove password and trusted token
    if (info != null) {
      Enumeration enumeration = info.keys();
      while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        Object anObj = info.get(key);
        // Log each property except for password and token.
        if (!TeiidURL.CONNECTION.PASSWORD.equalsIgnoreCase(key)) {
          logger.fine(key + "=" + anObj); // $NON-NLS-1$
        }
      }
    }
  }
Пример #16
0
 public void delete(GenericVO vo) throws AppException, SysException {
   StaffWorkAreaSVO staffWorkArea = (StaffWorkAreaSVO) vo;
   if (vo == null) {
     throw new RuntimeException();
   }
   StringBuffer sql = new StringBuffer("delete from STAFF_WORK_AREA where 1=1");
   sql.append(" and STAFF_WORK_AREA_ID=?");
   Connection connection = null;
   PreparedStatement ps = null;
   try {
     connection = ConnectionFactory.getConnection();
     ps = connection.prepareStatement(sql.toString());
     ps.setString(1, staffWorkArea.getStaffWorkAreaId());
     ps.execute();
   } catch (SQLException e) {
     throw new SysException("", "delete error..", e);
   } finally {
     try {
       if (ps != null) {
         ps.close();
       }
     } catch (SQLException e) {
     }
   }
 }
Пример #17
0
 public GenericVO findByPK(GenericVO vo) throws AppException, SysException {
   StaffWorkAreaSVO result = null;
   StaffWorkAreaSVO staffWorkArea = (StaffWorkAreaSVO) vo;
   StringBuffer sql = new StringBuffer("select");
   sql.append(
       " a.STAFF_WORK_AREA_ID,a.STAFF_ID,a.WORK_AREA_ID,a.GRANTOR,a.ADMIN_FLAG,a.STS,a.STS_DATE,a.CREATE_DATE");
   sql.append(" from STAFF_WORK_AREA a where 1=1");
   sql.append(" and STAFF_WORK_AREA_ID=?");
   Connection connection = null;
   PreparedStatement ps = null;
   ResultSet rs = null;
   try {
     connection = ConnectionFactory.getConnection();
     ps = connection.prepareStatement(sql.toString());
     ps.setString(1, staffWorkArea.getStaffWorkAreaId());
     rs = ps.executeQuery();
     result = (StaffWorkAreaSVO) ResultSetUtil.convertToVo(rs, StaffWorkAreaSVO.class);
   } catch (SQLException e) {
     throw new SysException("", "findByPK error..", e);
   } finally {
     try {
       if (rs != null) {
         rs.close();
       }
       if (ps != null) {
         ps.close();
       }
     } catch (SQLException e) {
     }
   }
   return result;
 }
Пример #18
0
  protected String getDropSQL(DatabaseObjectType type, String name) {
    SQLObject foundDropQuery = null;
    String sqlStatement = "DROP " + type.toString() + " " + name;

    for (SQLObject dropQuery : catalogStore.getDropStatements()) {
      if (type == dropQuery.getType()) {
        foundDropQuery = dropQuery;
        break;
      }
    }

    if (foundDropQuery != null
        && foundDropQuery.getSql() != null
        && !foundDropQuery.getSql().isEmpty()) {
      String dropStatement = foundDropQuery.getSql();
      StringBuffer sqlBuffer = new StringBuffer(dropStatement.length() + name.length());
      int identifier = dropStatement.indexOf('?');

      sqlBuffer
          .append(dropStatement.substring(0, identifier))
          .append(name)
          .append(dropStatement.substring(identifier + 1));
      sqlStatement = sqlBuffer.toString();
    }

    return sqlStatement;
  }
Пример #19
0
 public void delete(GenericVO vo) throws AppException, SysException {
   ProvinceSVO province = (ProvinceSVO) vo;
   if (vo == null) {
     throw new RuntimeException();
   }
   StringBuffer sql = new StringBuffer("delete from PROVINCE where 1=1");
   sql.append(" and PROV_ID=?");
   Connection connection = null;
   PreparedStatement ps = null;
   try {
     connection = ConnectionFactory.getConnection();
     ps = connection.prepareStatement(sql.toString());
     ps.setString(1, province.getProvId());
     ps.execute();
   } catch (SQLException e) {
     throw new SysException("", "delete error..", e);
   } finally {
     try {
       if (ps != null) {
         ps.close();
       }
     } catch (SQLException e) {
     }
   }
 }
Пример #20
0
  public static String getFooter(String context) {
    try {
      FileReader fileReader =
          new FileReader(findResourceOnFileSystem("servletResponseTemplate.htm"));
      BufferedReader buffread = new BufferedReader(fileReader);
      String templateFile = "", line;
      StringBuffer SBreader = new StringBuffer();
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line).append("\n");
      }
      fileReader.close();
      buffread.close();
      templateFile = SBreader.toString();
      templateFile =
          templateFile.replaceAll(
              "BOTTOMGRAPHIC", CommonConfiguration.getURLToFooterGraphic(context));

      int end_header = templateFile.indexOf("INSERT_HERE");
      return (templateFile.substring(end_header + 11));
    } catch (Exception e) {
      // out.println("I couldn't find the template file to read from.");
      e.printStackTrace();
      String error =
          "An error occurred while attempting to read from an HTML template file. This probably will not affect the success of the operation you were trying to perform.</p></body></html>";
      return error;
    }
  }
Пример #21
0
  public void testUnions() throws SQLException {
    String viewName = "v0";
    Statement stmt = createStatement();

    StringBuffer createView = new StringBuffer("create view " + viewName + " as select * from t0 ");
    for (int i = 1; i < 100; i++) {
      createView.append(" UNION ALL (SELECT * FROM t0 )");
    }
    // System.out.println(createViewString);
    stmt.executeUpdate(createView.toString());
    commit();

    int passCount = 0;
    for (int count = 1000; count <= 1000; count += 1000) {
      // keep testing until it fails
      if (largeUnionSelect(viewName, count)) break;
      passCount = count;
    }

    // 10000 gives a different constant pool error
    // DERBY-1315 gives out of memory error.
    // assertTrue("10000 UNION passed!",
    //        largeUnionSelect(viewName, 10000));

    createStatement().executeUpdate("DROP VIEW " + viewName);

    // svn 372388 trunk - passed @ 900
    // trunk now back to 700
    //
    assertEquals("UNION operators change from previous limit", 1000, passCount);
  }
  /**
   * Description of the Method
   *
   * @param db Description of the Parameter
   * @return Description of the Return Value
   * @throws SQLException Description of the Exception
   */
  public int update(Connection db) throws SQLException {
    int resultCount = 0;
    PreparedStatement pst = null;
    StringBuffer sql = new StringBuffer();

    sql.append(
        " UPDATE customer_product "
            + " SET description = ?, "
            + "     status_id = ?, "
            + "     status_date = ?, "
            + "     modified = "
            + DatabaseUtils.getCurrentTimestamp(db)
            + ", "
            + "     modifiedby = ?, "
            + "     enabled = ? ");
    sql.append("WHERE order_id = ? ");
    sql.append("AND modified " + ((this.getModified() == null) ? "IS NULL " : "= ? "));

    int i = 0;
    pst = db.prepareStatement(sql.toString());
    pst.setString(++i, this.getDescription());
    DatabaseUtils.setInt(pst, ++i, this.getStatusId());
    pst.setTimestamp(++i, this.getStatusDate());
    pst.setInt(++i, this.getModifiedBy());
    pst.setInt(++i, this.getId());
    if (this.getModified() != null) {
      pst.setTimestamp(++i, this.getModified());
    }
    pst.setBoolean(++i, this.getEnabled());
    resultCount = pst.executeUpdate();
    pst.close();
    return resultCount;
  }
Пример #23
0
  private String md5(String data) {

    StringBuffer sb = new StringBuffer();

    try {
      MessageDigest messageDigest = MessageDigest.getInstance("MD5");
      messageDigest.update(data.getBytes());
      byte[] digestBytes = messageDigest.digest();

      /* convert to hexstring */
      String hex = null;

      for (int i = 0; i < digestBytes.length; i++) {
        hex = Integer.toHexString(0xFF & digestBytes[i]);

        if (hex.length() < 2) {
          sb.append("0");
        }
        sb.append(hex);
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }

    return sb.toString();
  }
Пример #24
0
  /**
   * Substitute actual data for the parameter markers to simulate parameter substitution in a
   * PreparedStatement.
   *
   * @param sql The SQL containing parameter markers to substitute.
   * @param list The parameter descriptors.
   * @param connection The current connection.
   * @return The modified SQL statement.
   */
  static String substituteParameters(String sql, ParamInfo[] list, ConnectionJDBC2 connection)
      throws SQLException {
    int len = sql.length();

    for (int i = 0; i < list.length; i++) {
      if (!list[i].isRetVal && !list[i].isSet && !list[i].isOutput) {
        throw new SQLException(
            Messages.get("error.prepare.paramnotset", Integer.toString(i + 1)), "07000");
      }

      Object value = list[i].value;

      if (value instanceof java.io.InputStream || value instanceof java.io.Reader) {
        try {
          if (list[i].jdbcType == java.sql.Types.LONGVARCHAR
              || list[i].jdbcType == java.sql.Types.CLOB
              || list[i].jdbcType == java.sql.Types.VARCHAR) {
            // TODO: Should improve the character set handling here
            value = list[i].getString("US-ASCII");
          } else {
            value = list[i].getBytes("US-ASCII");
          }
          // Replace the stream/reader with the String/byte[]
          list[i].value = value;
        } catch (java.io.IOException e) {
          throw new SQLException(Messages.get("error.generic.ioerror", e.getMessage()), "HY000");
        }
      }

      if (value instanceof String) {
        len += ((String) value).length() + 5;
      } else if (value instanceof byte[]) {
        len += ((byte[]) value).length * 2 + 4;
      } else {
        len += 32; // Default size
      }
    }

    StringBuffer buf = new StringBuffer(len + 16);
    int start = 0;

    for (int i = 0; i < list.length; i++) {
      int pos = list[i].markerPos;

      if (pos > 0) {
        buf.append(sql.substring(start, list[i].markerPos));
        start = pos + 1;
        final boolean isUnicode = connection.getTdsVersion() >= Driver.TDS70 && list[i].isUnicode;
        Support.embedData(buf, list[i].value, isUnicode, connection);
      }
    }

    if (start < sql.length()) {
      buf.append(sql.substring(start));
    }

    return buf.toString();
  }
 private static String modifyFile(String str) throws IOException {
   String search = "<jndi-binding type=\"XAPooledDataSource\"";
   String last_search = "</jndi-binding>";
   String newDB = "newDB_" + OSProcess.getId();
   String jndi_str =
       "<jndi-binding type=\"XAPooledDataSource\" jndi-name=\"XAPooledDataSource\"          jdbc-driver-class=\"org.apache.derby.jdbc.EmbeddedDriver\" init-pool-size=\"5\" max-pool-size=\"5\" idle-timeout-seconds=\"600\" blocking-timeout-seconds=\"6\" login-timeout-seconds=\"2\" conn-pooled-datasource-class=\"org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource\" xa-datasource-class=\"org.apache.derby.jdbc.EmbeddedXADataSource\" user-name=\"mitul\" password=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\" connection-url=\"jdbc:derby:"
           + newDB
           + ";create=true\" >";
   String config_prop =
       "<config-property>"
           + "<config-property-name>description</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>hi</config-property-value>"
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>user</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>jeeves</config-property-value>"
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>password</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a</config-property-value>        "
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>databaseName</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>"
           + newDB
           + "</config-property-value>"
           + "</config-property>\n";
   String new_str = jndi_str + config_prop;
   /*
    * String new_str = " <jndi-binding type=\"XAPooledDataSource\"
    * jndi-name=\"XAPooledDataSource\"
    * jdbc-driver-class=\"org.apache.derby.jdbc.EmbeddedDriver\"
    * init-pool-size=\"5\" max-pool-size=\"5\" idle-timeout-seconds=\"600\"
    * blocking-timeout-seconds=\"6\" login-timeout-seconds=\"2\"
    * conn-pooled-datasource-class=\"org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource\"
    * xa-datasource-class=\"org.apache.derby.jdbc.EmbeddedXADataSource\"
    * user-name=\"mitul\"
    * password=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\"
    * connection-url=\"jdbc:derby:"+newDB+";create=true\" > <property
    * key=\"description\" value=\"hi\"/> <property key=\"databaseName\"
    * value=\""+newDB+"\"/> <property key=\"user\" value=\"mitul\"/> <property
    * key=\"password\"
    * value=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\"/>";
    */
   int n1 = str.indexOf(search);
   getLogWriter().fine("Start Index = " + n1);
   int n2 = str.indexOf(last_search, n1);
   StringBuffer sbuff = new StringBuffer(str);
   getLogWriter().fine("END Index = " + n2);
   String modified_str = sbuff.replace(n1, n2, new_str).toString();
   return modified_str;
 }
Пример #26
0
 /**
  * Test in clause with many parameters
  *
  * @param numParams Number of parameters to test
  * @return true if the test fails
  * @throws SQLException
  */
 private boolean inClause(int numParams) throws SQLException {
   String testName = "IN clause with " + numParams + " parameters";
   StringBuffer sqlBuffer = new StringBuffer((numParams * 20) + 512);
   sqlBuffer.append("SELECT * FROM T0 WHERE SI IN (");
   for (int i = 1; i < numParams; i++) {
     sqlBuffer.append("?, ");
   }
   sqlBuffer.append("?)");
   return checkT0Query(testName, sqlBuffer, numParams, 2);
 }
Пример #27
0
 /**
  * 按条件删除数据
  *
  * @param conditions 查询条件
  * @return 删除的行数
  * @throws Exception
  */
 public int deleteByConditions(String conditions) throws Exception {
   StringBuffer buffer = new StringBuffer(100);
   buffer.append("DELETE FROM LwWholeSaleSummary WHERE ");
   buffer.append(conditions);
   if (logger.isDebugEnabled()) {
     logger.debug(buffer.toString());
   }
   int count = dbManager.executeUpdate(buffer.toString());
   return count;
 }
Пример #28
0
 public String convertToCommaDelimited(String[] list) {
   StringBuffer ret = new StringBuffer("");
   for (int i = 0; list != null && i < list.length; i++) {
     ret.append(list[i]);
     if (i < list.length - 1) {
       ret.append(',');
     }
   }
   return ret.toString();
 }
Пример #29
0
 public static String escapeBadSqlPatternChars(String s) {
   StringBuffer sb = new StringBuffer(s);
   for (int i = 0, len = sb.length(); i < len; ++i)
     if (sb.charAt(i) == '\'') {
       sb.insert(i, '\'');
       ++len;
       i += 2;
     }
   return sb.toString();
 }
  /**
   * コード一覧(新規領域)作成用メソッド。<br>
   * 領域番号と領域名称の一覧を取得する。 領域番号順にソートする。
   *
   * @param connection コネクション
   * @return  List
   * @throws ApplicationException
   */
  public static List selectRyoikiSinnkiInfoList(Connection connection) throws ApplicationException {

    // -----------------------
    // SQL文の作成
    // -----------------------
    StringBuffer select = new StringBuffer();

    select.append("SELECT DISTINCT");
    select.append(" RYOIKI_NO,"); // 領域番号
    select.append(" RYOIKI_RYAKU,"); // 領域名称
    select.append(" SETTEI_KIKAN"); // 設定期間
    select.append(" FROM MASTER_RYOIKI");
    select.append(" WHERE ZENNENDO_OUBO_FLG = '1'");
    select.append(" ORDER BY RYOIKI_NO");

    if (log.isDebugEnabled()) {
      log.debug("query:" + select);
    }

    // -----------------------
    // リスト取得
    // -----------------------
    try {
      return SelectUtil.select(connection, select.toString());
    } catch (DataAccessException e) {
      throw new ApplicationException("領域情報検索中にDBエラーが発生しました。", new ErrorInfo("errors.4004"), e);
    } catch (NoDataFoundException e) {
      throw new SystemException("領域マスタに1件もデータがありません。", e);
    }
  }