Galera, este é o meu código
public String[] insereEvento(Evento evento) throws TagITDAOException {
CallableStatement cstm = null;
String[] sRetorno = null;
String DATA = "05/01/2010 19:41:06";
try {
cstm = con.prepareCall("{call sp_inserir_evento(?, ?, ?, ?, ?, ?, ?, ?, ?)}");
cstm.setString(1, evento.getNome());
cstm.setDouble(2, evento.getVagasPrincipal());
cstm.setDate(3, converterData(evento.getInscInicio()));
cstm.setDate(4, converterData(evento.getInscTermino()));
cstm.setString(5, evento.getRua());
cstm.setString(6, evento.getCidade());
cstm.setDate(7, DATA);
cstm.setString(8, evento.getContato());
cstm.registerOutParameter(9, Types.VARCHAR);
cstm.execute();
sRetorno = cstm.getString(9).split(";");
cstm.close();
} catch (SQLException e) {
throw new TagITDAOException();
}
return sRetorno;
}
Eu estou passando para uma procedure uma data com hora em um campo datetime no meu banco sql, já tentei várias coisas mas não esta funcionando.
Eu quero inserir o campo DATA no meu campo datetime que fica na em
cstm.setDate(7, DATA);
O que devo fazer ?
Agradeço a ajuda.
[quote=Valter Henrique]Galera, este é o meu código
public String[] insereEvento(Evento evento) throws TagITDAOException {
CallableStatement cstm = null;
String[] sRetorno = null;
String DATA = "05/01/2010 19:41:06";
try {
cstm = con.prepareCall("{call sp_inserir_evento(?, ?, ?, ?, ?, ?, ?, ?, ?)}");
cstm.setString(1, evento.getNome());
cstm.setDouble(2, evento.getVagasPrincipal());
cstm.setDate(3, converterData(evento.getInscInicio()));
cstm.setDate(4, converterData(evento.getInscTermino()));
cstm.setString(5, evento.getRua());
cstm.setString(6, evento.getCidade());
cstm.setDate(7, DATA);
cstm.setString(8, evento.getContato());
cstm.registerOutParameter(9, Types.VARCHAR);
cstm.execute();
sRetorno = cstm.getString(9).split(";");
cstm.close();
} catch (SQLException e) {
throw new TagITDAOException();
}
return sRetorno;
}
Eu estou passando para uma procedure uma data com hora em um campo datetime no meu banco sql, já tentei várias coisas mas não esta funcionando.
Eu quero inserir o campo DATA no meu campo datetime que fica na em
cstm.setDate(7, DATA);
O que devo fazer ?
Agradeço a ajuda.[/quote]
tenta assim
Connection conn = minha conexao
String DATA = "05/01/2010 19:41:06";
String pattern = "dd/MM/yyyy hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
java.util.Date d = sdf.parse(DATA);
java.sql.Date sqlDate = null;
sqlDate = new java.sql.Date(d.getTime());
PreparedStatement stmt = conn.prepareStatement("sql");
stmt.setDate(1, sqlDate);
zoren
Outubro 22, 2010, 7:39am
#3
Se você quiser salvar a hora tbm, você tem que usar o setTimestamp no lugar de setDate
André e zoren, muito obrigado pelas dicas, no final o meu código ficou assim :
public String[] insereEvento(Evento evento) throws TagITDAOException {
CallableStatement cstm = null;
String[] sRetorno = null;
java.sql.Timestamp data = java.sql.Timestamp.valueOf("2005-04-06 09:01:10");
try {
cstm = con.prepareCall("{call sp_inserir_evento(?, ?, ?, ?, ?, ?, ?, ?, ?)}");
cstm.setString(1, evento.getNome());
cstm.setDouble(2, evento.getVagasPrincipal());
cstm.setDate(3, converterData(evento.getInscInicio()));
cstm.setDate(4, converterData(evento.getInscTermino()));
cstm.setString(5, evento.getRua());
cstm.setString(6, evento.getCidade());
cstm.setTimestamp(7, data);
cstm.setString(8, evento.getContato());
cstm.registerOutParameter(9, Types.VARCHAR);
cstm.execute();
sRetorno = cstm.getString(9).split(";");
cstm.close();
} catch (SQLException e) {
throw new TagITDAOException();
}
return sRetorno;
}
Funciona, perfeitamente, muito obrigado caras.