Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement insertion problem

 
Ashwin Sharma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have written a method which insert a statement in database as follows
Statement statement = connection.createStatement();
statement.execute(statementString);
connection.close();
but when i rerun my program to check whether the statement is inserted or not, it shows empty tuple. Can some body tell me why is my statement not inserted in database.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try executeUpdate instead of execute.
 
Steve McLeod
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you by chance not in database autocommit mode?

Try doing this after you obtain the connection:

connection.setAutoCommit(true);

Alternatively, after you have executed the sql, call connection.commit();
 
Ashwin Sharma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am already using "connection.setAutoCommit(true);"
Also executeUpdate is giving me same result.
if i use "statement.execute(statementString);" twice it is giving me error saying unique key violation. This means my syntax is proper and statement is executing properly. But on rerun the tuple is not there. I am using hsqldb.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like transaction rollback behaviour. Can we see your code?
 
Ashwin Sharma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After adding this line its working
connection.createStatement().execute("SHUTDOWN SCRIPT;"); but i dont know why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic