Jxls导出excel的若干方式总结(一)-- Jdbc方式( ResultSetCollection )


查询结果一条记录只能显示在一行,否则只显示第一行的部分。

模板中beans对象suplyArea后跟的是数据库表中的列名称。

Jxls导出excel的若干方式总结(一)-- Jdbc方式( ResultSetCollection )

List supplyAreaList = saBiz.getSupplyAreaById(supplyAreaId);
SupplyArea sa = (SupplyArea) supplyAreaList.get(0);
Long id = sa.getSupplyAreaId();
String templateDir = "D:/excel/template/SupplyAreaJDBC.xls";
String targetDir="D:/excel/export/testJDBC.xls";			
Map beans = new HashMap();
Class.forName("oracle.jdbc.driver.OracleDriver").getInterfaces();
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@168.9.202.49:1521:GIS", "JMJL","JMJL" );
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String query = "select SUPPLYAREA_ID,EDITUSER,SUPPLYAREA_NAME,X,Y,REMARKS,STARTDATE,ENDDATE,LIFECYCLE,DATAGUID from HSY_T_SUPPLYAREA where SUPPLYAREA_ID ="+id;
ResultSet rs = stmt.executeQuery(query);
ResultSetCollection rsc=new ResultSetCollection(rs,false);
beans.put("suplyArea",rsc);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(templateDir, beans, targetDir);


你可能感兴趣的:(Collection)