aspose file tools*
The moose likes JDBC and the fly likes problem with inserting data in a same column using prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with inserting data in a same column using prepared statement" Watch "problem with inserting data in a same column using prepared statement" New topic
Author

problem with inserting data in a same column using prepared statement

smyle khanna
Ranch Hand

Joined: Jan 14, 2004
Posts: 54
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

Joined: May 30, 2002
Posts: 1400
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 ]

- Varun
 
 
subject: problem with inserting data in a same column using prepared statement