This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
twin yan wrote:still doing the same thing , what's the diffrence between with ' and without it worked both ways
any ideas on what's wrong with my prepared statment ?
Ok ' are for strings, you are making something convert a striping to an Integer when it isn't required.
The syntax of your prepared statement looks fine to me, so we must start looking at other areas of concern.
I can see a few possible problems
1) does the select return data? You just say result.next Without first checking there is a row returned.
2) if date1 is a database date field just inserting a java default formatted date string could cause problems, much better to also make that a prepared statement then you can use the setDate method which is multi date format safe.
3) what values are returned from the select statement? Pop them into debugging statements to check the values, are they what you expect?
4) in your catch block simply use e.printStackTrace as that shows up red where ever the console output goes. You do know where console output goes?
Also, I don't know the details of MySQL concurrency model, but allocating a new ID by selecting the maximum ID first and incrementing that may fail in multiuser environments - if two people happen to execute this code at exactly the same time, they may end up using identical ID for the new record. Hopefully a primary key constraint would prevent that, but if you use auto increment column in MySQL, the database can allocate new IDs for you, in a way which is both more effective and safe in multiuser environment.