java - Can PreparedStatement.executeUpdate() ever return 0 on INSERT? -


is there condition under sql insert statement executed method executeupdate on preparedstatement object return 0 without throwing sqlexception?

for example:

string query = "insert mytable (column1,column2) values (5,6)"; preparedstatement preparedstatement = connection.preparestatement(query); if(preparedstatement.executeupdate()!=1){ // strange error has occurred } else{ // ever } 

why ask? check ensure number of rows returned equal 1 wonder if overkill if should never return 1.

so tried and, yes, can 0 return value insert statement. can happen if select * from table without rows into table. example, domain , domain2 have same schema , domain2 empty, doing following

connection con = datasource.getconnection(); preparedstatement ps = con.preparestatement("insert domain select * domain2"); system.out.println(ps.executeupdate()); 

prints 0.

the time i've ever used return value of executeupdate delete statement on 1 row make sure existed before , deleted. don't think should use insert.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -