コード例 #1
0
  // ---------------------------------------------------------------//
  public int editProject(Project project, Connection conn) throws SQLException {
    PreparedStatement prepStmt = null;
    int rtrn = -1;
    java.util.Date date = new java.util.Date();
    Timestamp currentdate = new Timestamp(date.getTime());
    conn = select();
    String sql =
        "UPDATE PROJECTS SET PROJ_NAME=?,MODIFIED_AT=?,MODIFIED_BY=?,PROJ_ACTIVE=?,PROJ_BUDGET=?,PROJ_DEADLINE=?,PROJ_DESCRIPTION=?,PROJ_FROM=?,PROJ_TYPE=?,PROJ_TO=?,CUST_ID=?,ROWVERSION=ROWVERSION+1"
            + "WHERE PROJ_ID=?";

    prepStmt = conn.prepareStatement(sql);
    prepStmt.setString(1, project.getName());

    prepStmt.setTimestamp(2, currentdate);

    prepStmt.setString(3, project.getModified_by());

    if (project.isActive()) prepStmt.setString(4, "Y");
    else prepStmt.setString(4, "N");

    if (project.getBudget() != -1) prepStmt.setFloat(5, project.getBudget());
    else prepStmt.setInt(5, 0);

    if (project.getNextDeadline() == null) prepStmt.setDate(6, null);
    else prepStmt.setDate(6, new java.sql.Date(project.getNextDeadline().getTime()));

    prepStmt.setString(7, project.getDescription());

    prepStmt.setDate(8, new java.sql.Date(project.getStartDate().getTime()));

    prepStmt.setString(9, project.getProjectType());

    if (project.getEndDate() == null) prepStmt.setDate(10, null);
    else prepStmt.setDate(10, new java.sql.Date(project.getEndDate().getTime()));

    prepStmt.setInt(11, project.getCustomerID());
    prepStmt.setInt(12, project.getProjectID());
    prepStmt.executeUpdate();
    rtrn = project.getProjectID();
    return rtrn;
  }
コード例 #2
0
 // ---------------------------------------------------------------//
 public int insertProject(Project project, Connection conn) throws SQLException {
   PreparedStatement prepStmt = null;
   int rtrn = -1;
   java.util.Date date = new java.util.Date();
   Timestamp currentdate = new Timestamp(date.getTime());
   conn = select();
   String sql =
       "INSERT INTO PROJECTS(PROJ_ID,PROJ_NAME,INSERTED_AT,INSERTED_BY,MODIFIED_AT,MODIFIED_BY,PROJ_ACTIVE,PROJ_BUDGET,PROJ_DEADLINE,PROJ_DESCRIPTION,PROJ_FROM,PROJ_TYPE,PROJ_TO,CUST_ID,ROWVERSION)"
           + " VALUES(PROJ_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
   String cols[] = {"PROJ_ID"};
   prepStmt = conn.prepareStatement(sql, cols);
   prepStmt.setString(1, project.getName());
   prepStmt.setTimestamp(2, currentdate);
   prepStmt.setString(3, project.getInserted_by());
   prepStmt.setDate(4, null);
   prepStmt.setString(5, null);
   if (project.isActive()) prepStmt.setString(6, "Y");
   else prepStmt.setString(6, "N");
   if (project.getBudget() != -1) prepStmt.setFloat(7, project.getBudget());
   else prepStmt.setInt(7, 0);
   if (project.getNextDeadline() == null) prepStmt.setDate(8, null);
   else prepStmt.setDate(8, new java.sql.Date(project.getNextDeadline().getTime()));
   prepStmt.setString(9, project.getDescription());
   prepStmt.setDate(10, new java.sql.Date(project.getStartDate().getTime()));
   prepStmt.setString(11, project.getProjectType());
   if (project.getEndDate() == null) prepStmt.setDate(12, null);
   else prepStmt.setDate(12, new java.sql.Date(project.getEndDate().getTime()));
   prepStmt.setInt(13, project.getCustomerID());
   prepStmt.setInt(14, project.getRowversion());
   prepStmt.executeUpdate();
   ResultSet rs = prepStmt.getGeneratedKeys();
   if (rs.next()) {
     rtrn = rs.getInt(1);
   }
   rs.close();
   return rtrn;
 }