• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement is not executing on setString

 
Cecil Westerhof
Greenhorn
Posts: 4
Java Netbeans IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code works:


I use it with the jar I got from:
www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

When I remove the comment and try to insert the first record two times, I get the following error with the next setString:


This is just to show the problem. I hit on the problem when inserting more as 2000 records, but this is a little easier to demonstrate. ;-)

What is happening here and how to solve it?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although it shouldn't be necessary, have you tried setting the values again before executing the query? It's possible that driver doesn't retain them. Also the code "catch (Exception e) {}" is a bad practice. You should always handle your exceptions.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your CREATE TABLE statement I observe that the name column is Unique! This will prevent subsequent inserts with same value!
 
Cecil Westerhof
Greenhorn
Posts: 4
Java Netbeans IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Selikoff wrote:Although it shouldn't be necessary, have you tried setting the values again before executing the query? It's possible that driver doesn't retain them. Also the code "catch (Exception e) {}" is a bad practice. You should always handle your exceptions.


I did not, but that is not the problem, because this is only to show the problem. To be really sure I changed the code:


Still the same problem.

Also in my real program I handle the exception. Here I am just generating the exception to show the problem.
 
Cecil Westerhof
Greenhorn
Posts: 4
Java Netbeans IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhan Sundararajan Devaki wrote:From your CREATE TABLE statement I observe that the name column is Unique! This will prevent subsequent inserts with same value!

The problem is not that I can not insert the same twice (that I am doing on purpose to show the problem), the problem is that after the exception isgenerated, the statement setSting generates an exception "statement is not executing".
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, one possible reason could be, the preparedstatement object could be in an inconsistent state after an exception and is being prevented from being executed.
 
Cecil Westerhof
Greenhorn
Posts: 4
Java Netbeans IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhan Sundararajan Devaki wrote:I believe, one possible reason could be, the preparedstatement object could be in an inconsistent state after an exception and is being prevented from being executed.

Okay, when doing the prep = conn.prepareStatement again, there is no problem. But this still leaves me with my real problem. I did get the "statement is not executing" after inserting a little more as 2.000 records. The way I 'solved' it was by not inserting more as a 1.000 records pro program run. Now I do the prep = conn.prepareStatement again every 1000 inserts. But why is this necessary?
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you commit after execution? If not, you should and then repeat the cycle (create prepared statement, set values, etc... ) for the required number of records.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic