/**
* 批量导入数据
* @param listInsert
* @throws SQLException
*/
public void insertList(List<Device> listInsert) throws SQLException
{
@SuppressWarnings("deprecation")
PreparedStatement ps = getSession().connection().prepareStatement("insert into uhome_device("
+ "dev_reg_flag, dev_model_code, dev_mac) "
+ "values(?,?,?)");
for (Device device:listInsert)
{
ps.setObject(1, device.getRegFlag());
ps.setObject(2, device.getModelCode());
ps.setObject(3, device.getMac());
);
ps.addBatch();
}
ps.executeBatch();
}
* 批量导入数据
* @param listInsert
* @throws SQLException
*/
public void insertList(List<Device> listInsert) throws SQLException
{
@SuppressWarnings("deprecation")
PreparedStatement ps = getSession().connection().prepareStatement("insert into uhome_device("
+ "dev_reg_flag, dev_model_code, dev_mac) "
+ "values(?,?,?)");
for (Device device:listInsert)
{
ps.setObject(1, device.getRegFlag());
ps.setObject(2, device.getModelCode());
ps.setObject(3, device.getMac());
);
ps.addBatch();
}
ps.executeBatch();
}

本文介绍了一种使用Java和SQL批量导入设备数据的方法。通过预编译的SQL语句和批处理执行来提高数据插入效率。具体操作包括设置SQL参数、添加批处理并执行批处理命令。
1万+

被折叠的 条评论
为什么被折叠?



