Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with inserting data in a same column using prepared statement

 
smyle khanna
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am having a problem in inserting the data into database,i have 2 insert 4 rows into a column n every thing the last row overwrites the rest n only the last row is displayed in the database
the code is blow,plz help me slove this problem...
the opt1,opt2,opt3 are over written by opt4 n only opt4 is there is the database
thanks in advance...
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing abnormal happening here I believe.
You are making only one insert and hence one row is getting inserted.
Only opt4 is getting inserted only because of this line :
pstat1.setString(2,opt4);
Replace opt4 with opt3, then only a row with opt3 will appear.
Make 4 inserts (instead of one) in order to insert 4 rows.
You may also go for a batch insert.
[ March 16, 2004: Message edited by: Varun Khanna ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic