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.
Hi can any one of you tell me why i am unable to insert values into MYsql.
I wrote a jsp page where i am trying to insert data through Java bean into Mysql.
i am ableprint all fileds in jsp page but in mysql all the columns are Zero. when i try to re enter the same valuse its giving me Duplicate error
'ERROR 1062 (23000): Duplicate entry '0' for key 2'
the code in Bean is following String sqlstmt="insert into user_details(fname,lname,uname,pwd,rpwd,age,email,remail,phone,mobile,addr) values(fname='"+fname+"',lname='"+lname+"',uname='"+uname+"',pwd='"+pwd+"',rpwd='"+rpwd+"',age="+age+",email='"+email+"',remail='"+remail+"',phone="+phone+",mobile="+mobile+",addr='"+addr+"')";
System.out.println(sqlstmt); int i=st.executeUpdate(sqlstmt);
Yep, I would have to suspect the same. Use one of the MySQL gui tools, Query Browser or Admistrator, and look at the details of your table. You should be able to see the second key and determine the duplicate value.
If you do not have a gui tool use the command line client. Below are the helpful commands.
show keys from tableName show columds from tableName
If you have enabled logging, you can check the log to determine which values caused the error.
After you determine the duplication column/value, change the code to use a prepared statement. In fact, I am guessing there are more blocks of code that should be using prepared statements