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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
Posts: 38921
686
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?
 
Marshal
Posts: 67164
169
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 ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!