aspose file tools*
The moose likes JDBC and the fly likes how do i insert more than one row to my table 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 "how do i insert more than one row to my table" Watch "how do i insert more than one row to my table" New topic
Author

how do i insert more than one row to my table

varsha rao
Greenhorn

Joined: Mar 06, 2006
Posts: 26
hello there,
This is the code snippet iv written
but the problem is its not inserting all the items in the String object , its inserting only the first value i.e l[0] and kp[0]. What corrections should i make to insert all the elements of the String object
please let me know the corrections.
Regards
varsha
void insertResults(String l[],String kp[],String tName)throws Exception
{
Connect();
String cmd="insert into "+tName+" values(?,?)";
PreparedStatement pst=null;
pst=con.prepareStatement(cmd);
for(int i=0;i<kp.length;i++)
{

pst.setString(1,l[i]);
pst.setString(2,kp[i]);
pst.executeUpdate();
pst.clearParameters();
}
pst.close();
}
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
There's nothing wrong with that that I can see, although clearParameters is unneeded; it should be harmless functionally and not really significant in terms of performance..

It's possible that the 2nd insert is throwing an exception, perhaps because of a constraint violation, so look at your exception logs, if you haven't.

It's also possible that your driver/database is simply broken and doesn't support this correctly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i insert more than one row to my table