コード例 #1
0
  public boolean insertCompanyDetails(CompanyDetails com) {
    boolean check = true;
    PreparedStatement ps;
    if (dbc.connect()) {
      try {
        String sqlQuery = "INSERT INTO " + COMPANY_INFO + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
        ps = dbc.getConnection().prepareStatement(sqlQuery);
        ps.setNString(1, com.getTenCtyVN());
        ps.setString(2, com.getTenCtyEN());
        ps.setString(3, com.getTenVietTat());
        ps.setNString(4, com.getTenGiamDoc());
        ps.setString(5, com.getSoDienThoai());
        ps.setString(6, com.getSoFax());
        ps.setString(7, com.getSoTaiKhoan());
        ps.setNString(8, com.getDiaChiVN());
        ps.setNString(9, com.getDiaChiEN());
        ps.setString(10, com.getMaSoThue());
        if (com.getNgayDangKy() == null) {
          ps.setNull(11, java.sql.Types.DATE);
        } else {
          ps.setDate(11, com.getNgayDangKy());
        }

        ps.setBytes(12, com.getLogo());

        if (ps.executeUpdate() < 1) {
          check = false;
        }
      } catch (SQLException ex) {
        Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return check;
  }
コード例 #2
0
  public CompanyDetails getCompanyDetails() {
    CompanyDetails com = new CompanyDetails();
    PreparedStatement ps;
    ResultSet rs;
    if (dbc.connect()) {
      try {
        String sqlQuery = "select * from " + COMPANY_INFO;
        ps = dbc.getConnection().prepareStatement(sqlQuery);
        rs = ps.executeQuery();
        while (rs.next()) {
          com.setTenCtyVN(rs.getNString(1));
          System.out.println(rs.getNString(1));
          com.setTenCtyEN(rs.getString(2));
          com.setTenVietTat(rs.getString(3));
          com.setTenGiamDoc(rs.getNString(4));
          com.setSoDienThoai(rs.getString(5));
          com.setSoFax(rs.getString(6));
          com.setSoTaiKhoan(rs.getString(7));
          com.setDiaChiVN(rs.getNString(8));
          com.setDiaChiEN(rs.getNString(9));
          com.setMaSoThue(rs.getString(10));
          com.setNgayDangKy(rs.getDate(11));
          com.setLogo(rs.getBytes(12));
        }

      } catch (SQLException ex) {
        Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return com;
  }