Beispiel #1
0
 // update Record will take the two arguemts one as the StudentList and other
 // one is the RecordList recordList1
 public void updateRecord(List<Student> studentList, List<Record> recordList) {
   Student student2 = new Student();
   Record record2 = new Record();
   String studentid;
   Iterator<Student> itr = studentList.iterator();
   while (itr.hasNext()) {
     student2 = (Student) itr.next();
   }
   studentid = student2.getStudentId();
   String bookRecordId;
   Iterator<Record> itr1 = recordList.iterator();
   while (itr1.hasNext()) {
     record2 = (Record) itr1.next();
   }
   bookRecordId = record2.getBookRecord();
   Connection con = ConnectionUtils.getConnection();
   String query = "UPDATE BookRecord set status=?,studentId=? where bookRecordId=? ";
   try {
     PreparedStatement statement = con.prepareStatement(query);
     statement.setString(1, "issued");
     statement.setString(2, student2.getStudentId());
     statement.setString(3, record2.getBookRecord());
     int result = statement.executeUpdate();
   } catch (Exception ex) {
     throw new IllegalStateException(ex);
   } finally {
     try {
       con.close();
     } catch (Exception ex1) {
       throw new IllegalStateException(ex1);
     }
   }
 }
Beispiel #2
0
  // change the name in the issue Service for createRecord to
  // createSearchBookRecord
  public void createSearchRecord(Record record) {
    // TODO Auto-generated method stub
    List<Record> recordList1 = new ArrayList<Record>();
    Connection con = ConnectionUtils.getConnection();

    String query =
        "SELECT bookRecordId,bookId,status,studentId from BookRecord where bookRecordId =?";
    try {
      PreparedStatement statement = con.prepareStatement(query);
      statement.setString(1, record.getBookRecord());
      ResultSet resultSet = statement.executeQuery();
      while (resultSet.next()) {
        Record record1 = new Record();
        record1.setBookRecord(resultSet.getString("bookRecordId"));
        record1.setBookId(resultSet.getString("bookId"));
        record1.setStatus(resultSet.getString("status"));
        record1.setStudentId(resultSet.getString("studentId"));
        recordList1.add(record1);
      }
    } catch (Exception ex) {
      throw new IllegalStateException(ex);
    } finally {
      try {
        con.close();
      } catch (Exception ex1) {
        throw new IllegalStateException(ex1);
      }
    }
    searchedRecordList = recordList1;
  }
Beispiel #3
0
  private PreparedStatement populateCreateRecordStatement(Record record, Connection con)
      throws SQLException {
    String query = "INSERT into BookRecord values(?,?,?,?)";

    PreparedStatement statement = con.prepareStatement(query);
    statement.setString(1, record.getBookRecord());
    statement.setString(2, record.getBookId());
    statement.setString(3, record.getStatus());
    statement.setString(4, record.getStudentId());
    return statement;
  }