This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I just performed an INSERT within my JSP page, but I need to return the value of the primary key which was generated by the database to the next JSP page. I tried to perform another query within the same connection, but I'm having problems (Before start of result set, etc.) What's the easiest way to do this? Thanks, Drew
as for the first question, read this post: http://www.coderanch.com/t/297502/JDBC/java/know-last-auto-increment-number I don't know if this is what you want to achieve, but it might guide you... for the second error: when you get an error like "Before start of result set" it means that after you perform a query your result set is placed one position before the first row that has been retrieved. So if you want to access the resultset you have to do something like this FIRST: result.next() now you are located in the first row and can access it. hope it helps
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Joined: May 13, 2001
Hey, Thanks - that was exactly what I want. I was able to get this to work with: LAST_INSERT_ID() I'm not sure it's ideal since it only works with MySQL, AFAIK. Did you find a more portable solution? Drew
Joined: Nov 27, 2001
as you read on my post, I think I was complicating myself. As David suggested me, I did not use the database to generate my unique ID. I used System.currentTimeMillis() and played with this number a little bit. Now all the files that I have uploaded so far have a unique name. not the best solution... i guess... but it's pretty straighforward.. cheers