A query that works in management studio and in the executeUpdate
makes that same executeUpdate
return -1
, which is undefined in any documentation we can find. Its supposed to return only the rowcount or 0
. What does this mean? The driver is the JDBC-ODBC bridge if that matters.
Example:
String query = "IF NOT EXISTS (SELECT * FROM animals WHERE animal_name ='" + a +"') INSERT INTO " + table + " (animal_name, animal_desc, species_id) VALUES ('" + a + "', '" + b + "', " + c + ")";
int result = statement.executeUpdate(query);
System.out.println(result);
The query works, as the row is added to the database, it's just strange that it returns -1 where the documentation says it will only return 0 or the rowcount (as I've been corrected).
UPDATE:
Running this in Management Studio results with "Command completed successfully."
IF NOT EXISTS (SELECT * FROM animals WHERE animal_name = 'a')
INSERT INTO animals(animal_name, animal_desc, species_id) VALUES ('a', 'a', 1)
That should mean the method should return 0 because it doesn't return anything, correct?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…