java jdbc 批處理數據 SqlServer數據庫

//批量修改
	public void zxupdate(List<InstRData> instlist) {
		Connection conn = getConnection(); // 得到鏈接
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
		String sql = "update   InstRData  set LastPrice=?,BidPrice=?,AskPrice=?,TradeVolume=?,TradeAmount=?,DataTime=?    WHERE InstCode =?";
		ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
		for (int i = 0; i < instlist.size(); i++) {
			ps.setFloat(1, instlist.get(i).getLastPrice());
			ps.setFloat(2, instlist.get(i).getBidPrice());
			ps.setFloat(3, instlist.get(i).getAskPrice());
			ps.setFloat(4, instlist.get(i).getTradeVolume());
			ps.setFloat(5, instlist.get(i).getTradeAmount());
			ps.setTimestamp(6, instlist.get(i).getDataTime());
			ps.setString(7, instlist.get(i).getInstCode());
			ps.addBatch();
		}
		int[] executeBatch = ps.executeBatch();
		System.out.println(Arrays.toString(executeBatch));
		
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			close(rs, ps, conn);
		}
		
		
	}
相關文章
相關標籤/搜索