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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

prepareStatement returns 0?  RSS feed

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a problem. PrepareStatement returns 0 in my code but the query returns the correct result in my sql editor?!

I�m working within a servlet. First I do make a database connection and share that connection through the servlet lifetime... Inside the doPost method I first call a synchronized method which do the following task:

synchronized method_1 ()
1) SELECT MAX(id)
2) UPDATE date for the max(id) (I use type 2 historic)
3) INSERT request values
4) SELECT MAX(id) (from the insert)
5) return new MAX(id)

- That works fine. After that I call yet another synchronized method where I do the same task, just in another table:

synchronized method_2 ( int invoiceID )
1) SELECT MAX(id) returns 0 //FAILS!
2) ...

I close my resultSet after every Query. I have tried to close my preparedStatement too (stat.close()). I have also tried to close my connection after doing the task in each synchronized method, and open a new connection. That doesn�t work either...

The code looks like the following:




[ January 29, 2005: Message edited by: Jeppe Fjord ]
[ January 29, 2005: Message edited by: Jeppe Fjord ]
 
author & internet detective
Marshal
Posts: 38508
653
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Jeppe,
Are you sure the inserts are being committed to the database? Also, out of curiousity, why are you using a synchronized method rather than a transaction?
 
Author and ninkuma
Marshal
Posts: 66787
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Jeppe, please do not re-post the same question more than once. Please continue any discussion in the original post.
[ January 29, 2005: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!