• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to insert data into mysql

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

can any body please help me on the same.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you are trying to insert duplicate values for some UNIQUE column.
What is the schema of the table? Also, what are the values that are being passed as part of the query?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the JDBC forum where database questions go.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:)
 
reply
    Bookmark Topic Watch Topic
  • New Topic