| Author |
statement is not executing on setString
|
Cecil Westerhof
Greenhorn
Joined: Jul 05, 2011
Posts: 4
|
|
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
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
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.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Madhan Sundararajan Devaki
Ranch Hand
Joined: Mar 18, 2011
Posts: 312
|
|
|
From your CREATE TABLE statement I observe that the name column is Unique! This will prevent subsequent inserts with same value!
|
S.D. MADHAN
Not many get the right opportunity !
|
 |
Cecil Westerhof
Greenhorn
Joined: Jul 05, 2011
Posts: 4
|
|
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
Joined: Jul 05, 2011
Posts: 4
|
|
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
Joined: Mar 18, 2011
Posts: 312
|
|
|
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
Joined: Jul 05, 2011
Posts: 4
|
|
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
Joined: Mar 18, 2011
Posts: 312
|
|
|
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.
|
 |
 |
|
|
subject: statement is not executing on setString
|
|
|