• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

statement is not executing on setString

 
Greenhorn
Posts: 4
Netbeans IDE Suse Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Suse Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Suse Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Suse Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic