@Override public List<Exposicao> consultaNomeExposicao(String data) throws SQLException { String sql = "SELECT titulo, CONVERT(varchar(5), horario, 108) as hora from exposicao " + "where ? >= dataInicio and ? <= dataFim"; PreparedStatement ps = c.prepareStatement(sql); ps.setString(1, data); ps.setString(2, data); ResultSet rs = ps.executeQuery(); List<Exposicao> lista = new ArrayList<Exposicao>(); while (rs.next()) { Exposicao expo = new Exposicao(); expo.setTituloExibicao(rs.getString("titulo")); SimpleDateFormat formatador = new SimpleDateFormat("HH:mm"); Date horario; try { horario = formatador.parse(rs.getString("hora")); Time time = new Time(horario.getTime()); expo.setHora(time); } catch (ParseException e1) { e1.printStackTrace(); } lista.add(expo); } return lista; }
@Override public void insereExposicao(Exposicao e) throws SQLException { String sql = "INSERT INTO exposicao (titulo, dataInicio, dataFim, exibicaoEspecial, horario) VALUES (?,?,?,?,?)"; PreparedStatement ps; ps = c.prepareStatement(sql); ps.setString(1, e.getTituloExibicao()); java.sql.Date dtI = new java.sql.Date(e.getDataInicio().getTime()); ps.setDate(2, dtI); java.sql.Date dtF = new java.sql.Date(e.getDataFim().getTime()); ps.setDate(3, dtF); ps.setInt(4, e.getExibicaoEspecial()); // ps.setString(5, e.getHorario()); ps.executeUpdate(); ps.close(); }
public Exposicao salvaExposicao() { Exposicao e = new Exposicao(); e.setTituloExibicao(txtEvento.getText().toString()); String dataInicio = txtDataInicio.getText(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); try { e.setDataInicio(sdf.parse(dataInicio)); } catch (ParseException e2) { e2.printStackTrace(); } String dataFim = txtDataFim.getText(); SimpleDateFormat sdf_ = new SimpleDateFormat("dd/MM/yyyy"); try { e.setDataFim(sdf_.parse(dataFim)); } catch (ParseException e1) { e1.printStackTrace(); } SimpleDateFormat formatador = new SimpleDateFormat("HH:mm"); Date hora; try { hora = formatador.parse(txtHorario.getText()); Time time = new Time(hora.getTime()); e.setHorario(time); } catch (ParseException e1) { e1.printStackTrace(); } if (rdbtnNao.isSelected()) { e.setExibicaoEspecial(0); } else { if (rdbtnSim.isSelected()) { e.setExibicaoEspecial(1); } } return e; }