public void addFlowCardDetail(String flowCardVouNo,
List flowCardDetailList) throws DaoException {
Connection conn=null;
try{
//加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//实例名
String url ="jdbc:oracle:thin:@localhost:1521:orcl";
String username="test";
String password = "test";
//关闭自动提交事务
conn.setAutoCommit(false);
//拼接sql语句
StringBuffer sbSql = new StringBuffer();
sbSql.append("insert into t_flow_card_detail (flow_card_no,aim_client_id,");
sbSql.append("item_no,opt_qty,adjust_flay)");
sbSql.append("values (?,?,?,?,?)");
PreparedStatement pstmt = null;
//建立连接Connection
conn = DriverManager.getConnection(url, username, password)
//预编译sql语句
pstmt = conn.prepareStatement(sbSql.toString());
for (Iterator iter = flowCardDetailList.iterator();iter.hasNext();) {
FlowCardDetail flowCardDetail = iter.next();
pstmt.setString(1, flowCardVouNo);
pstmt.setInt(2, flowCardDetail.getAimClient().getId());
pstmt.setString(3, flowCardDetail.getItem().getItemNo());
pstmt.setBigDecimal(4, flowCardDetail.getOptQty());
pstmt.setString(5, flowCardDetail.getAdjustFlag());
//添加一条sql语句,即把一条sql命令添加到命令列表中
pstmt.addBatch();
}
//批量执行sql语句
pstmt.executeBatch();
//提交事务,真正的将操作执行到数据库
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
throw new DaoException(e);
} finally {
ConnectionManager.close(pstmt);
}
}
注释:
选择Tools——ODBCImporter,因为我们导入的是excel,所以选择Excel Files
选在Excel所在的路径,选中要导入的Excel,点击确定
在Data from ODBC选项下,双击excel路径,在下面可以预览导入的数据
切换到Data to Oracle选项卡下,填写要导入到哪个数据库的哪张表,必须在Fields中选中一列之后,Import按钮才可用,此时导入的已经是整张excel了,最后点击Import按钮,成功导入
注意事项: