0

The Code:

sql = "INSERT INTO `admin` (`id`,`username`,`password`,`access`) VALUES ('"+(numIds+1)+"','"+addedUsername+"','"+addedPassword+"','"+addedAccess+"');";

Statement statementAdd = (Statement) DBconnection.createStatement();
result = statementAdd.executeUpdate(sql);

The Error:

MySQLLogin.java:133: error: incompatible types
            result = statementAdd.executeUpdate(sql);
                                               ^
required: ResultSet
found:    int
1 error

Any ideas?

2

3 Answers 3

4

ExecuteUpdate returns integer it seems you are assigning it to the Result set

Sign up to request clarification or add additional context in comments.

2 Comments

How would I change this then?
int count = statementAdd.executeUpdate(sql);
0

For this:

'"+(numIds+1)+"'

You are either trying to do math with a string or insert a string with into a numeric field. Given your error message, I suspect the latter. It's the single quotes that make it a string.

Comments

0

executeUpdate returns the number of rows affected (in your case, it will return the number of rows inserted. But you are trying to a assign the returning int to a ResultSet object.

So just change it to :

int insertedRows = statementAdd.executeUpdate(sql);

See the javadocs for Statement class for more information.

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.