Reputation: 2911
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
Upvotes: 0
Views: 1294
Reputation: 7940
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.
Upvotes: 1
Reputation: 1058
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.
Upvotes: 1
Reputation: 1102
Returns: either
(1) the row count for SQL Data Manipulation Language (DML) statements or
(2) 0 for SQL statements that return nothing
Upvotes: 0