Exemple #1
0
 @SuppressWarnings("rawtypes")
 public void createTables() {
   try {
     Set<Class> tableClasses = getTableBeans();
     for (Class klass : tableClasses) {
       int result = dao.createTable(klass);
       if (result == 1) LOG.info("Create success, {}");
       else if (result == 0) LOG.info("Exist table, {}");
     }
   } catch (Exception e) {
     LOG.error("Create tables fail, ", e);
   }
 }
Exemple #2
0
  // 도서 등록
  public int InsertData(Book bean) {
    System.out.println(bean.toString());
    String sql =
        "insert into books(bookcode, name, volume, writer, publisher, pubdate, genre, image, bookstat, bookstory) ";
    sql += " values(bookseq.nextval, ?, ?, ?, ?, to_date(?, 'yyyy/MM/dd'), ?, ?, default, ?) ";
    PreparedStatement pstmt = null;
    int cnt = -99999;
    try {
      if (conn == null) {
        super.conn = super.getConn();
      }
      conn.setAutoCommit(false);
      pstmt = super.conn.prepareStatement(sql);

      pstmt.setString(1, bean.getName());
      pstmt.setInt(2, bean.getVolume());
      pstmt.setString(3, bean.getWriter());
      pstmt.setString(4, bean.getPublisher());
      pstmt.setString(5, bean.getPubdate());
      pstmt.setString(6, bean.getGenre());
      // 책 이미지 이름은 책 제목과 책 볼륨의 문자열 조합이다.
      String image = bean.getName() + " " + bean.getVolume() + ".jpg";
      pstmt.setString(7, image);
      // pstmt.setString(8, bean.getBookstat());
      pstmt.setString(8, bean.getBookstory());

      cnt = pstmt.executeUpdate();
      conn.commit();
    } catch (Exception e) {
      SQLException err = (SQLException) e;
      cnt = -err.getErrorCode();
      e.printStackTrace();
      try {
        conn.rollback();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    } finally {
      try {
        if (pstmt != null) {
          pstmt.close();
        }
        super.closeConn();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
    return cnt;
  }
Exemple #3
0
  // 책 한건의 정보를 편집하기 위함
  public int UpdateData(Book bean) {
    // System.out.println( "업뎃" + bean.toString() );
    String sql = "update books set ";
    sql += " name=?, volume=?, writer=?, publisher=?, pubdate=to_date(?, 'yyyy/MM/dd'), ";
    sql += " genre=?, bookstory=?  ";
    sql += " where bookcode = ? ";

    PreparedStatement pstmt = null;
    int cnt = -99999;
    try {
      if (conn == null) {
        super.conn = super.getConn();
      }
      conn.setAutoCommit(false);
      pstmt = super.conn.prepareStatement(sql);
      pstmt.setString(1, bean.getName());
      pstmt.setInt(2, bean.getVolume());
      pstmt.setString(3, bean.getWriter());
      pstmt.setString(4, bean.getPublisher());
      pstmt.setString(5, bean.getPubdate());
      pstmt.setString(6, bean.getGenre());
      pstmt.setString(7, bean.getBookstory());
      pstmt.setInt(8, bean.getBookcode());

      cnt = pstmt.executeUpdate();
      conn.commit();
    } catch (Exception e) {
      SQLException err = (SQLException) e;
      cnt = -err.getErrorCode();
      e.printStackTrace();
      try {
        conn.rollback();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    } finally {
      try {
        if (pstmt != null) {
          pstmt.close();
        }
        super.closeConn();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
    return cnt;
  }
Exemple #4
0
  // 한건의 책을 삭제하기위함.
  // 삭제를 해도 데이터베이스에서 삭제되는것이 아니라 대여상태가 대출 불가로 바뀜.
  public int bookDelete(int bookcode) {
    // System.out.println( "업뎃" + bean.toString() );
    String sql = "update books set ";
    sql += " bookstat='대출 불가' ";
    sql += " where bookcode = ? ";

    PreparedStatement pstmt = null;
    int cnt = -99999;
    try {
      if (conn == null) {
        super.conn = super.getConn();
      }
      conn.setAutoCommit(false);
      pstmt = super.conn.prepareStatement(sql);

      pstmt.setInt(1, bookcode);

      cnt = pstmt.executeUpdate();
      conn.commit();
    } catch (Exception e) {
      SQLException err = (SQLException) e;
      cnt = -err.getErrorCode();
      e.printStackTrace();
      try {
        conn.rollback();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    } finally {
      try {
        if (pstmt != null) {
          pstmt.close();
        }
        super.closeConn();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
    return cnt;
  }
Exemple #5
0
 public void save(Storable bean) {
   if (!dao.exist(bean)) taskQueue.add(bean);
   else LOG.info("Exist Storable: {}", bean);
 }