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.
PS noob here
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.
executeUpdate(query)返回受影响的行数,这意味着如果表中没有行,那么将返回0,如果表中有行,那么表的总行数。
Returns: either
(1) the row count for SQL Data Manipulation Language (DML) statements or
(2) 0 for SQL statements that return nothing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.