Olá pessoal, eu estou tentando fazer um UPDATE no meu banco de dados e não estou conseguindo de jeito nenhum. Está dando erro na consulta. Aqui está o código do meu UPDATE:
private boolean salvarPessoa()
{
String dateInsc = jCampoDataInsc.getText();
String dateVenc = jCampoDataVenc.getText();
String nome = jCampoNome.getText();
String endereco = jCampoEndereco.getText();
String telefone = jCampoTelefone.getText();
int peso = Integer.parseInt(jCampoPeso.getText());
String altura = jCampoAltura.getText();
Connection conexao = null;
PreparedStatement stm = null;
ResultSet rs = null;
String mudar = "UPDATE academia.pessoas"
+ "SET Nome = ?, Endereco = ?, Telefone = ?, Peso = ?, Altura = ?, Data_Inscricao = ?, Data_Vencimento = ?"
+ "WHERE ID = ?";
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date dataInsc = null;
java.util.Date dataVenc = null;
try
{
formatter.setLenient(false);
dataInsc = formatter.parse(dateInsc);
dataVenc = formatter.parse(dateVenc);
}
catch (ParseException ex)
{
JOptionPane.showMessageDialog(mainPanel, "Digite uma data válida", "Erro", JOptionPane.ERROR_MESSAGE);
return false;
}
java.sql.Date dataInscSql = new java.sql.Date(dataInsc.getTime());
java.sql.Date dataVencSql = new java.sql.Date(dataVenc.getTime());
if (dateInsc.trim().length() != formatter.toPattern().length())
{
JOptionPane.showMessageDialog(mainPanel, "Digite uma data válida", "Erro", JOptionPane.ERROR_MESSAGE);
return false;
}
if (dateVenc.trim().length() != formatter.toPattern().length())
{
JOptionPane.showMessageDialog(mainPanel, "Digite uma data válida", "Erro", JOptionPane.ERROR_MESSAGE);
return false;
}
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException ex)
{
System.out.println("Classe não encontrada");
}
try
{
conexao = (Connection) DriverManager.getConnection("jdbc:mysql://", "root", "mustaine");
System.out.println("A conexão foi um sucesso\n");
}
catch (SQLException ex)
{
System.out.println("SQL Exception... Erro na conexão");
}
try
{
stm = conexao.prepareStatement(mudar);
}
catch (SQLException ex)
{
System.out.println("SQL Exception... Erro ao criar objeto Statement:");
}
try
{
stm.setString(1, nome);
stm.setString(2, endereco);
stm.setString(3, telefone);
stm.setInt(4, peso);
stm.setString(5, altura);
stm.setDate(6, dataInscSql);
stm.setDate(7, dataVencSql);
stm.setInt(8, ID);
stm.executeUpdate();
JOptionPane.showMessageDialog(mainPanel, "Pessoa editada com sucesso!", "Confirmacao", JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException ex)
{
System.out.println("SQL Exception... Erro na consulta");
}
try
{
System.out.println("\nFechando a conexão...");
conexao.close();
System.out.println("\nConexão fechada");
return true;
}
catch(SQLException erro)
{
System.out.println("Erro no fechamento");
}
return false;
}