2

Xlsファイルのアップロード中に以下のコードがあり、Xlsシートの最後の行まで以下のメソッド呼び出しを行い、StringBuilderに値を追加しています。

     public boolean insertBatch(Connection con, int projectId, int venueId, String batchName, String examStartDate, String examStartTime, String examEndTime, String reportingStartTime, String reportingEndTime, int totalSeats) {
    String  this.query = new StringBuilder().append("insert into venue_batch ( batch_code  ,exam_venue_id  ,exam_date  ,exam_start_time  ,exam_end_time  ,reporting_start_time  ,reporting_end_time  ,total_seats,tranID) VALUES ('").append(batchName).append("' ,").append(venueId).append(" ,'").append(stDate).append("' ,'").append(examStartTime).append("'  ,'").append(examEndTime).append("' ,'").append(reportingStartTime).append("' ,'").append(reportingEndTime).append("' ,").append(totalSeats).append(" )").toString();
                try {
                    this.stmt = con.createStatement();
                    count = this.stmt.executeUpdate(this.query);
                    this.stmt.close();
                } catch (SQLException ex) {
                    System.out.println(new StringBuilder().append("Venue # insertBatch # SQLException").append(ex.toString()).toString());
                    onUploadFail(con, "Please try again!");
                }
    }

*I need to add Unique Transaction id(VenueTranId) to DB at the last during executeUpdate(this.query), in the above  Query  how to Proceed below is Transaction id code.Thanks All..

          Calendar calendar = Calendar.getInstance();
      Long lngTime = Long.valueOf(calendar.getTimeInMillis());
      String VenueTranId=lngTime.toString();
4

1 に答える 1

0

StringBuilderを変数に格納して、後で必要なものを追加できるようにします。

public boolean insertBatch(Connection con, int projectId, int venueId, String    batchName, String examStartDate, String examStartTime, String examEndTime, String reportingStartTime, String reportingEndTime, int totalSeats) {
StringBuilder query = new StringBuilder();
query.append("insert ");
query.append("more blabla ");

try {
  this.stmt = con.createStatement();
  count = this.stmt.executeUpdate(this.query.toString());
  this.stmt.close();
} catch (SQLException ex) {
                query.append(" Failed: "+ex.getMessage());
} finally {
  String VenueTranId = computeId();
  query.append(VenueTranId);
}
于 2013-01-06T12:27:13.467 に答える