Banco de dados insere valores na tabela, mas retorna um erro

2 respostas
F

Pessoal, o meu banco está inserindo na tabela, mas retorna o seguinte erro.

try {

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://localhost:1433;"
                    + "databaseName=teste;user=sa;password=123;";
            try {

                Connection con = DriverManager.getConnection(connectionUrl);

                // executar uma query
                Statement st = (Statement) con.createStatement();
                String mySelect = "Insert into tb_Pessoa(id_Pessoa,nome,telefone) values (4,'Felipe','[telefone removido]')";
                ResultSet rs = st.executeQuery(mySelect);

ERRO:

com.microsoft.sqlserver.jdbc.SQLServerException: A instrução não retornou um conjunto de resultados.

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:783)

at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)

at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:611)

at teste_banco.Conexao_Banco.conectar(Conexao_Banco.java:37)

at teste_banco.Main.main(Main.java:20)

2 Respostas

otaviojava

tanto inserção, atualização ou remoção ele não retorna nenhuma informação.
Tanta usar o método execute se eu não me engano não retorna nada.

O

Bom dia.

Ao invez de chamar “executeQuery” chame “executeUpdate”.

Att,

Criado 4 de julho de 2011
Ultima resposta 4 de jul. de 2011
Respostas 2
Participantes 3