Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

In this page you can find the example usage for java.sql ResultSet getDate.

Prototype

java.sql.Date getDate(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Date object in the Java programming language.

Usage

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SupplierDAOImpl.java

@Override
public Supplier getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_supplier WHERE supplier_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Supplier>() {

        @Override//from  w w w.  j  av a2s  .  co m
        public Supplier mapRow(ResultSet rs, int i) throws SQLException {
            Supplier s = new Supplier();
            s.setId(rs.getInt("supplier_id"));
            s.setSupplierName(rs.getString("supplier_name"));
            s.setAddress(rs.getString("address"));
            s.setContact(rs.getString("contact"));
            s.setEmail(rs.getString("email"));
            s.setAddedDate(rs.getDate("added_date"));
            s.setStatus(rs.getBoolean("status"));
            return s;
        }
    });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SupplierDAOImpl.java

@Override
public List<Supplier> getALL() throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_supplier";

    return jdbcTemplate.query(sql, new RowMapper<Supplier>() {

        @Override/*from   w w  w. j av a2 s.c  o  m*/
        public Supplier mapRow(ResultSet rs, int i) throws SQLException {
            Supplier s = new Supplier();
            s.setId(rs.getInt("supplier_id"));
            s.setSupplierName(rs.getString("supplier_name"));
            s.setAddress(rs.getString("address"));
            s.setContact(rs.getString("contact"));
            s.setEmail(rs.getString("email"));
            s.setAddedDate(rs.getDate("added_date"));
            s.setStatus(rs.getBoolean("status"));

            return s;
        }
    });
}

From source file:DataCharts.Chart.java

private CategoryDataset createCategoryDataset(ArrayList<YearData> locs) {

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final String series1 = "Customers";

    try {//  w  w  w.ja va2 s  . co m
        ResultSet locations = db.selectDataColumn("customer", "*");

        Calendar defCal = Calendar.getInstance();
        defCal.set(2015, 1, 1);
        int defMonthNum = defCal.get(Calendar.MONTH);
        Month defMonth = new Month(defMonthNum, 2015);
        dataset.addValue(0, series1, defMonth.toString());

        defCal = Calendar.getInstance();
        defCal.set(2015, 6, 6);
        defMonthNum = defCal.get(Calendar.MONTH);
        defMonth = new Month(defMonthNum, 2015);
        dataset.addValue(0, series1, defMonth.toString());

        //   while(locations.next()){

        ResultSet jobDates = db.selectDataColumn("jobs", "*");
        int n = 0;
        Month month = null;
        while (jobDates.next()) {

            Calendar cal = Calendar.getInstance();
            cal.setTime(jobDates.getDate("date"));
            int monthNum = cal.get(Calendar.MONTH);
            month = new Month(monthNum, 2015);
            if (month != null) {
                dataset.addValue(1, series1, month.toString());
            }
        }

        // }
        return dataset;
    } catch (SQLException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.abcd.employeemaven.dao.impl.EmployeeDaoImpl.java

public Employee mapData(ResultSet rs) throws SQLException {
    Employee employee = new Employee();
    employee.setId(rs.getInt("employee_id"));
    employee.setFirstName(rs.getString("employee_first_name"));
    employee.setLastName(rs.getString("employee_last_name"));
    employee.setEmail(rs.getString("email"));
    employee.setAddress(rs.getString("address"));
    employee.setJoinedDate(rs.getDate("joined_date"));
    employee.setModifiedDate(rs.getDate("modified_date"));
    employee.setEffectiveDate(rs.getDate("effective_date"));
    employee.setStatus(rs.getBoolean("status"));
    return employee;
}

From source file:com.company.dao.impl.StudentDAOImpl.java

private Student mapData(ResultSet rs) throws SQLException {
    Student student = new Student();
    student.setId(rs.getInt("id"));
    student.setFirstName(rs.getString("first_name"));
    student.setLastName(rs.getString("last_name"));
    student.setEmail(rs.getString("email"));
    student.setContactNo(rs.getString("contact_no"));
    student.setGender(rs.getString("gender"));
    student.setDob(rs.getDate("dob"));
    student.setStatus(rs.getBoolean("status"));
    student.setAddedDate(rs.getDate("added_date"));
    student.setModifedDate(rs.getDate("modified_date"));
    student.setDeletedDate(rs.getDate("delete_date"));
    student.setDeleteIP(rs.getString("delete_ip"));
    return student;
}

From source file:Manager.getAllEmployees.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* www  .ja v a  2 s  .c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //json to pass back to our ajax request
    JSONArray jsonArray = new JSONArray();
    PrintWriter printout = response.getWriter();
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw");

        Statement st = con.createStatement();

        String query = "SELECT * FROM [MatchesFromAbove].[dbo].[Employee] WHERE active=1";

        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {

            JSONObject employeeToAdd = new JSONObject();
            employeeToAdd.put("ssn", rs.getString("SSN"));
            employeeToAdd.put("role", rs.getString("Role"));
            employeeToAdd.put("rate", rs.getInt("Rate"));
            employeeToAdd.put("startdate", rs.getDate("StartDate").toString());
            jsonArray.add(employeeToAdd);
        }
        //set the content type of our response
        response.setContentType("application/json");
        //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function.

        printout.print(jsonArray);
        printout.flush();
    } catch (Exception e) {
        printout.println("NO IDEA");
        return;
    }
}

From source file:biblivre3.acquisition.request.RequestDAO.java

private RequestDTO populateDto(ResultSet rs) throws Exception {
    final RequestDTO dto = new RequestDTO();
    dto.setSerial(rs.getInt("serial_requisition"));
    dto.setRequestDate(rs.getDate("requisition_date"));
    dto.setUser(rs.getString("responsable"));
    dto.setAuthorType(rs.getString("author_type"));
    dto.setAuthor(rs.getString("author"));
    dto.setAuthorNumeration(rs.getString("num_prename"));
    dto.setAuthorTitle(rs.getString("author_title"));
    dto.setTitle(rs.getString("item_title"));
    dto.setSubtitle(rs.getString("item_subtitle"));
    dto.setEditionNumber(rs.getString("edition_number"));
    dto.setPublisher(rs.getString("publisher"));
    dto.setObs(rs.getString("obs"));
    dto.setStatus(rs.getString("status"));
    dto.setRequester(rs.getString("requester"));
    dto.setQuantity(rs.getInt("quantity"));
    return dto;//w  w  w  .j a  v  a  2s .c o  m
}

From source file:com.reactivetechnologies.analytics.store.ModelJdbcRepository.java

@Override
public RegressionModel findOne(String id) {
    final List<RegressionModel> models = new ArrayList<>();
    jdbcTemplate.query(SELECT_MODEL.replaceFirst("@", id), new RowCallbackHandler() {

        @Override/*from   ww w .  j  a  v a  2  s. co  m*/
        public void processRow(ResultSet rs) throws SQLException {
            RegressionModel m = new RegressionModel();
            try {
                m.deserializeClassifierFromJson(rs.getString(1));
                //m.setLongId(rs.getLong(2));
                m.setStringId(rs.getString(2));
                m.setGeneratedOn(rs.getDate(3).getTime());
                models.add(m);
            } catch (IOException e) {
                throw new SQLException("Unable to deserialze model from string", e);
            }

        }
    });
    return models.isEmpty() ? null : models.get(0);
}

From source file:data.DefaultExchanger.java

protected void putDate(JsonGenerator generator, String fieldName, ResultSet rs, short index)
        throws SQLException, IOException {
    generator.writeFieldName(fieldName);
    Date date = rs.getDate(index);
    if (date == null) {
        generator.writeNull();/*  ww  w  .jav a 2  s .  c  o m*/
    } else {
        generator.writeNumber(date.getTime());
    }
}

From source file:net.bhira.sample.api.jdbc.EmployeeRowMapper.java

/**
 * Constructor for EmployeeRowMapper that creates an instance of
 * {@link net.bhira.sample.model.Employee} from row represented by rowNum in the given
 * ResultSet.//from ww w . j a  v a 2 s .c  o m
 * 
 * @param rs
 *            an instance of ResultSet to be processed.
 * @param rowNum
 *            integer representing the row number in ResultSet.
 */
@Override
public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
    Employee employee = new Employee();
    employee.setId(rs.getLong("id"));
    employee.setCompanyId(rs.getLong("companyid"));
    employee.setDepartmentId(rs.getLong("departmentid"));
    employee.setName(rs.getString("name"));
    employee.setManagerId(rs.getLong("managerid"));
    employee.setSalutation(rs.getString("salutation"));
    employee.setDOB(rs.getDate("dob"));
    employee.setTitle(rs.getString("title"));

    String sex = rs.getString("sex");
    if (sex != null) {
        employee.setSex(Employee.Sex.valueOf(sex));
    }

    employee.setAddress(rs.getString("addr"));
    employee.setCreated(rs.getTimestamp("created"));
    employee.setModified(rs.getTimestamp("modified"));
    employee.setCreatedBy(rs.getString("createdby"));
    employee.setModifiedBy(rs.getString("modifiedby"));
    return employee;
}