Bom dia pessoa!
Tenho um formulário onde a pessoa digita a data e e hora. Gostaria de saber como pegar essa data que está em uma mascara e salvar em uma coluna do formato “datetime”.
Estou usando esse método para salvar
try { Class.forName(driver); Connection con = DriverManager.getConnection(url, user, pass); String sql = "INSERT INTO Resultado (ORDEM,LINHA,LINHA_TIPO,LINHA_SETOR,RCTESTE,BPCS,DPERFIL" + "PROJETO,OEM,N_DESENHO,N_PLANO,OPERACAO,EQUIPAMENTO,DTESTE,RCOMPLEMENTO,RCTESTE" + "ESPEC_MIN,ESPEC_MAX,ESPEC_UNID,ESPEC_TEXTO,REFERENCIA,FREQUENCIA,FREQ_UNID,PRODUTO" + "ORIGEM,RTIPO,ESPEC_TEXTO,ESPECIFICACAO,LAB,ENCONTRADO,ENCONT_TEXTO,OBS,APROVADO,DATA,HORA,REGISTRO) VALUES (?)"; PreparedStatement pst = con.prepareStatement(sql); for (int i = 0; i < CadresultadoTabela.getRowCount(); i++) {
int Ordem = Integer.parseInt(CadresultadoTabela.getValueAt(i, 1).toString()); String Linha = (CadresultadoTabela.getValueAt(i, 2).toString()); String Linha_Tipo = (CadresultadoTabela.getValueAt(i, 3).toString()); String Setor = (CadresultadoTabela.getValueAt(i, 4).toString()); int Perfil = Integer.parseInt(CadresultadoTabela.getValueAt(i, 5).toString()); String Bpcs = (CadresultadoTabela.getValueAt(i, 6).toString()); String Desc_Perfil = (CadresultadoTabela.getValueAt(i, 7).toString()); String Projeto = (CadresultadoTabela.getValueAt(i, 8).toString()); String OEM = (CadresultadoTabela.getValueAt(i, 9).toString()); String Nº_Desenho = (CadresultadoTabela.getValueAt(i, 10).toString()); String Nº_Plano = (CadresultadoTabela.getValueAt(i, 11).toString()); String Operação = (CadresultadoTabela.getValueAt(i, 12).toString()); String Equipamento = (CadresultadoTabela.getValueAt(i, 13).toString()); String Desc_Teste = (CadresultadoTabela.getValueAt(i, 14).toString()); String Complemento = (CadresultadoTabela.getValueAt(i, 15).toString()); String Cod_Teste = (CadresultadoTabela.getValueAt(i, 16).toString()); int Espec_Min = Integer.parseInt(CadresultadoTabela.getValueAt(i, 17).toString()); int Espec_Max = Integer.parseInt(CadresultadoTabela.getValueAt(i, 18).toString()); String Espec_Unid = (CadresultadoTabela.getValueAt(i, 19).toString()); String Espec_Texto = (CadresultadoTabela.getValueAt(i, 20).toString()); String Referência = (CadresultadoTabela.getValueAt(i, 21).toString()); int Frequência = Integer.parseInt(CadresultadoTabela.getValueAt(i, 22).toString()); String Freq_Unid = (CadresultadoTabela.getValueAt(i, 23).toString()); String Produto = (CadresultadoTabela.getValueAt(i, 24).toString()); String Origem = (CadresultadoTabela.getValueAt(i, 25).toString()); String Tipo = (CadresultadoTabela.getValueAt(i, 26).toString()); String Especificação = (CadresultadoTabela.getValueAt(i, 27).toString()); String Freq_Texto = (CadresultadoTabela.getValueAt(i, 28).toString()); String Laboratorio = (CadresultadoTabela.getValueAt(i, 29).toString()); String Resultado_Numerico = (CadresultadoTabela.getValueAt(i, 30).toString()); String Resultado_Texto = (CadresultadoTabela.getValueAt(i, 31).toString()); String Observação = (CadresultadoTabela.getValueAt(i, 32).toString()); String Aprovado = (CadresultadoTabela.getValueAt(i, 33).toString());
pst.setInt(1, Ordem); pst.setString(2, Linha); pst.setString(3, Linha_Tipo); pst.setString(4, Setor); pst.setInt(5, Perfil); pst.setString(6, Bpcs); pst.setString(7, Desc_Perfil); pst.setString(8, Projeto); pst.setString(9, OEM); pst.setString(10, Nº_Desenho); pst.setString(11, Nº_Plano); pst.setString(12, Operação); pst.setString(13, Equipamento); pst.setString(14, Desc_Teste); pst.setString(15, Complemento); pst.setString(16, Cod_Teste); pst.setInt(17, Espec_Min); pst.setInt(18, Espec_Max); pst.setString(19, Espec_Unid); pst.setString(20, Espec_Texto); pst.setString(21, Referência); pst.setInt(22, Frequência); pst.setString(23, Freq_Unid); pst.setString(24, Produto); pst.setString(25, Origem); pst.setString(26, Tipo); pst.setString(27, Especificação); pst.setString(28, Freq_Texto); pst.setString(29, Laboratorio); pst.setString(30, Resultado_Numerico); pst.setString(31, Resultado_Texto); pst.setString(32, Observação); pst.setString(33, Aprovado); pst.setString(34, txt_data.getText()); pst.setString(35, txt_hora.getText()); pst.setString(36, txt_registro.getText());