package Beans;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.loggin
If we take a look at the Statement.executeUpdate javadoc we see that it always return 0 for DDL statements (in your case create table is a DDL statement):
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
You can assume that the statement execution is successful if you don't get a SQLException
.
st.executeUpdate()
either returns the row count for SQL Data Manipulation Language (DML) statements or0
for SQL statements that return nothing.
Creating a table is neither an INSERT nor an UPDATE, so it's normal to receive 0
as no row(s) were affected.
I am bit doubted about your query as well, you might need to look at this
CREATE TABLE `test1` ( contact_id INT(10),name VARCHAR(40),
birthdate DATE,PRIMARY KEY (contact_id));
If the update happens correctly then the value is 1, if not its 0. Moreover, it return 0 when your statement does not affect any row , for example in DDL execution it may return 0.