>

Fórum

Fórum da RL System, voltado para analistas, programadores etc. Tudo sobre linguagem de programação e desenvolvimento Full Stack: Banco de Dados, Android, C#, Java, .NET, PHP, Node, Javascript, TypeScript, Front, HTML e muito mais.



Banco de dados no JAVA


Estou com uma problema para inserir dados no banco, o mesmo está dando seguinte erro:

HTTP Status 500 ? Internal Server Error
Message java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
Description The server encountered an unexpected condition that prevented it from fulfilling the request.


Segue código JAVA abaixo.


try {
Class.forName("com.mysql.jdbc.Driver");
String SQLInsert = "INSERT INTO chamados (titulo, conteudo) , values (";
SQLInsert += " ' " + titulo + "' , '" + conteudo + " ');";

try {
Connection conect = DriverManager.getConnection("jdbc:mysql://localhost/chamados", "root" , "alegria1991");
Statement stm = conect.createStatement();
stm.executeQuery(SQLInsert);
stm.close();
conect.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
} catch (ClassNotFoundException e1) {
throw new RuntimeException(e1);
}
}



1 Resposta


Olá

O comando está diferente do curso, você precisa usar um PreparedStatement para comandos INSERT, DELETE etc.