0
import java.sql.*;
class ConnectionTest {
    public static void main(String... args)throws Exception {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("Jdbc:Odbc:myjdbc1", "sri", "tiger");
        System.out.println(con);
        Statement st = con.createStatement();
        System.out.println(st);
        String query = "delete logindetails";
        int count = st.executeUpdate(query);
        if(count == 0) 
        System.out.println("no records to delete");
        else 
        System.out.println("deleted successfullly");
        con.close();
    }
}

Hello World..!! My Question is.. What value is being assigned to integer variable count in int count = st.executeUpdate(query);
What does it assigns after it deleted all the rows..
and what does it assigns if there are already 0 rows in my table and no rows are deleted..?

Detailed explanation is much appreciated.
P.S. noob here

1

3 Answers 3

1

executeUpdate(query) returns number of rows affected this implies if there are no rows in the table then 0 will be returned and if there are rows in table then total rowcount of table.

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

1 Comment

Done. I dont think too much explanation is needed, its straight forward.
1

From official docs: Returns: either the row count for SQL Data Manipulation Language (such as INSERT, UPDATE or DELETE) statements or 0 for SQL statements that return nothing

@Update

It assigns the number of deleted rows.

Comments

0

Returns: either

(1) the row count for SQL Data Manipulation Language (DML) statements or

(2) 0 for SQL statements that return nothing

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.