0

The code is showing the error in .executeUpdate statement. I tried to execute the sql statement through Java. The error is showing in the line

rs = stmt.executeUpdate(upquery);

And the error is : Incompatible Types Found: int Required: java.sql.ResultSet;

Before starting the coding i imported certain things globally:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

Action code:

try{
    int srl = Integer.parseInt(srlTF.getText());
    String date = dateTF.getText();
    String part = paTF.getText();
    float amt = Float.parseFloat(amtTF.getText());
    float exp = Float.parseFloat(expTF.getText());
    float pro = Float.parseFloat(proTF.getText());
        Class.forName("com.mysql.jdbc.Driver");
    String usr = "root";
    String pwd = "root";
    String DB_URL = "jdbc:mysql://localhost/accounts?user="+usr+"&password="+pwd;
    con = DriverManager.getConnection(DB_URL);
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CLOSE_CURSORS_AT_COMMIT);
    String upquery = "insert into hostmargin_acc values(" + srl +","+ "'"+ date +","+ part +","+ amt +","+ exp +","+ pro + ");" ;
    rs = stmt.executeUpdate(upquery);
    msgLB.setText("BrO! Pwolichu! Save Chietu Kallan");
    }
    catch (Exception ex){
        System.out.println(ex.getMessage());
    }
1
  • You have a mismatched apostrophe - ... "'"+ date +"," .... Commented Sep 9, 2015 at 13:50

2 Answers 2

1

executeUpdate returns the number of rows affected. Try

String upquery = "insert into hostmargin_acc values(?, ?, ?, ?, ?, ?)";
PreparedStatement statement = 
              connection.prepareStatement(upquery,                                                                                               
                 ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CLOSE_CURSORS_AT_COMMIT);
statement.setInt(1, srl);
// set more params...
int rows = statement.executeUpdate();
Sign up to request clarification or add additional context in comments.

Comments

0

executeUpdate() returns an integer to indicate whether the operation was successful or not. You are collecting the returned int variable in a variable of type ResultSet, hence the error.

similar problem you can look this link. [Exception generated when updating table - java

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.