1、最近项目基本进入最后阶段了,然后会统计一下各个数据库的各个数据表的数据量,开始使用的报表工具,report-designer,开源的,研究了两天,发现并不是很好使,最后自己下班回去,晚上思考,想着还不如自己做一个,领导下命令,说这个活给你了,你做好给经理就行了。然后就开始不断的做。思路大概如下所示:

第一步,链接各个数据源,由于项目的数据库牵扯到mysql数据库,postgresql数据库,greenplum数据库,然后mysql里面有十几个库,每个库里面有相同的数据表,然后postgresql和greenplum是一个数据库有相同的数据表。由于greenplum集群版性能很好,所以对于大数据量的话,用greenplum进行查询十分方便快捷,也是关系型数据库,和mysql的语法基本性一致。不扯这个了。

第二步,由于使用了maven项目的,所以引入依赖就行了。由于greenplum的jar包,在maven仓库里面没有找到,我就在maven项目的classpath里面引入了公司的包,如下所示:

在.classpath里面,最下面加入这一行,就引入我这个jar包。这个是公司/lib项目里面的jar包,greenplum的依赖回头再找一下。

 <classpathentry kind="lib" path="/lib/jdbc/greenplum.jar"/>

依赖如下所示:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.</modelVersion>
<groupId>com.charts</groupId>
<artifactId>com.fline.aic.charts</artifactId>
<packaging>war</packaging>
<version>0.0.-SNAPSHOT</version>
<name>com.fline.aic.charts Maven Webapp</name>
<url>http://maven.apache.org</url> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.pivotal/greenplum-jdbc -->
<!-- <dependency>
<groupId>com.pivotal</groupId>
<artifactId>greenplum-jdbc</artifactId>
<version>5.1.</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version></version>
</dependency> </dependencies>
<build>
<finalName>com.fline.aic.charts</finalName>
</build> </project>

第三步、我使用了db.properties文件。放到src\main\resources路径下面。然后由于牵扯到公司信息,这里面放了大概23个url连接。

形如如下所示:

 #.db_xxx
db_xxx_driver=com.mysql.jdbc.Driver
db_xxx_url=jdbc:mysql://xxx:3306/db_xxx
db_xxx_user=xxx db_xxx_password=xxx
......

第四步,搞一个连接的工具类。大概搞23个这样的东西,重复代码就行了,然后测试一下看看是否能够连接成功。

 package com.fline.aic.utils;

 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle; /**
*
* @Description TODO
* @author biehl
* @Date 2018年9月21日 上午9:32:04
*
*/
public class JdbcUtils { //
private static String db_xxx_driver;
private static String db_xxx_url;
private static String db_xxx_user;
private static String db_xxx_password; //
static {
db_xxx_driver = ResourceBundle.getBundle("db").getString("db_xxx_driver");
db_xxx_url = ResourceBundle.getBundle("db").getString("db_xxx_url");
db_xxx_user = ResourceBundle.getBundle("db").getString("db_xxx_user");
db_xxx_password = ResourceBundle.getBundle("db").getString("db_xxx_password");
} /**
* 1
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getxxxConnection() throws ClassNotFoundException, SQLException {
// 加载数据库驱动
Class.forName(db_xxx_driver);
// System.out.println("测试加载数据库成功");
Connection con = DriverManager.getConnection(db_xxx_url, db_xxx_user, db_xxx_password);
// System.out.println("测试数据库链接成功");
return con;
} /**
*
* @param con
* @param ps
* @param rs
*/
public static void closeConnection(Connection con, PreparedStatement ps, ResultSet rs) {
if (rs != null) {// 关闭资源,避免出现异常
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void main(String[] args) {
try {
JdbcUtils.getxxxConnection();
System.out.println("xxx前置库连接成功.....");
System.out.println("======================================="); } catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} }

第五步、搞一个实体类,简写了这里。

 package com.fline.aic.vo;

 import java.io.Serializable;

 /**
*
* @Description TODO
* @author biehl
* @Date 2018年9月21日 上午10:50:47
*
*/
public class CountEntity implements Serializable { /**
*
*/
private static final long serialVersionUID = 1L;
private Integer sx;// xx
private Integer bj;// xx
private Integer yh;// xx
private Integer zz;// xx public Integer getSx() {
return sx;
} public void setSx(Integer sx) {
this.sx = sx;
} public Integer getBj() {
return bj;
} public void setBj(Integer bj) {
this.bj = bj;
} public Integer getYh() {
return yh;
} public void setYh(Integer yh) {
this.yh = yh;
} public Integer getZz() {
return zz;
} public void setZz(Integer zz) {
this.zz = zz;
} public CountEntity(Integer sx, Integer bj, Integer yh, Integer zz) {
super();
this.sx = sx;
this.bj = bj;
this.yh = yh;
this.zz = zz;
} public CountEntity() {
super();
} @Override
public String toString() {
return "CountEntity [sx=" + sx + ", bj=" + bj + ", yh=" + yh + ", zz=" + zz + "]";
} }

第六步、查询一下,统计报表数据量。

package com.fline.aic.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import com.fline.aic.utils.JdbcUtils;
import com.fline.aic.vo.CountEntity; /**
*
* @Description TODO
* @author biehl
* @Date 2018年9月21日 上午10:33:03
*
*/
public class QueryDataOfCharts { private static QueryDataOfCharts queryDataOfCharts; private QueryDataOfCharts() {
} public static QueryDataOfCharts getInstance() {
if (queryDataOfCharts == null) {
queryDataOfCharts = new QueryDataOfCharts();
}
return queryDataOfCharts;
} public Connection con = null;
public PreparedStatement ps = null;
public ResultSet rs = null; /**
* 1
*
* @return
*/
public CountEntity queryDbxxx() {
try {
Connection xxxConnection = JdbcUtils.getxxxConnection();
String sql = "select\r\n"
+ " (sx_directory.sx + sx_general_basic.sx + sx_general_extend.sx + sx_general_material.sx + sx_general_fee_project.sx + sx_general_questions.sx + sx_punish_basic.sx + sx_punish_questions.sx + sx_handle_basic.sx + sx_handle_material.sx + sx_handle_questions.sx + sx_public_basic.sx + sx_public_extend.sx + sx_public_material.sx + sx_public_fee_project.sx + sx_public_questions.sx + sx_check_basic.sx + sx_check_questions.sx + sx_zone_organization.sx) as sx,(bj_pro_accept.bj + bj_pro_process.bj + bj_pro_result.bj + bj_pro_specialprocedure.bj + bj_pro_material.bj) as bj,(yh_uc_province_user.yh + yh_uc_corporator_identity.yh + yh_uc_corporator_account.yh + yh_uc_info_enterprise.yh + yh_uc_info_association.yh + yh_uc_info_central_dept.yh + yh_uc_gov_org.yh + yh_uc_gov_region.yh + yh_uc_gov_staff.yh) as yh,(zz_lic_data.zz) as zz\r\n"
+ "from \r\n"
+ "(select count(1) as sx from up_task_directory) as sx_directory JOIN\r\n"
+ "(select count(1) as sx from up_task_general_basic) as sx_general_basic ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_general_extend) as sx_general_extend ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_general_material) as sx_general_material ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_general_fee_project) as sx_general_fee_project ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_general_questions) as sx_general_questions ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_punish_basic) as sx_punish_basic ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_punish_questions) as sx_punish_questions ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_handle_basic) as sx_handle_basic ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_handle_material) as sx_handle_material ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_handle_questions) as sx_handle_questions ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_public_basic) as sx_public_basic ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_public_extend) as sx_public_extend ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_public_material) as sx_public_material ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_public_fee_project) as sx_public_fee_project ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_public_questions) as sx_public_questions ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_check_basic) as sx_check_basic ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_task_check_questions) as sx_check_questions ON 1=1 JOIN\r\n"
+ "(select count(1) as sx from up_zone_organization) as sx_zone_organization ON 1=1 JOIN\r\n"
+ "(select count(1) as bj from up_pro_accept) as bj_pro_accept ON 1=1 JOIN\r\n"
+ "(select count(1) as bj from up_pro_process) as bj_pro_process ON 1=1 JOIN\r\n"
+ "(select count(1) as bj from up_pro_result) as bj_pro_result ON 1=1 JOIN\r\n"
+ "(select count(1) as bj from up_pro_specialprocedure) as bj_pro_specialprocedure ON 1=1 JOIN\r\n"
+ "(select count(1) as bj from up_pro_material) as bj_pro_material ON 1=1 JOIN \r\n"
+ "(select count(1) as yh from up_uc_province_user) as yh_uc_province_user ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_corporator_identity) as yh_uc_corporator_identity ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_corporator_account) as yh_uc_corporator_account ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_info_enterprise) as yh_uc_info_enterprise ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_info_association) as yh_uc_info_association ON 1=1 JOIN \r\n"
+ "(select count(1) as yh from up_uc_info_central_dept) as yh_uc_info_central_dept ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_gov_org) as yh_uc_gov_org ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_gov_region) as yh_uc_gov_region ON 1=1 JOIN\r\n"
+ "(select count(1) as yh from up_uc_gov_staff) as yh_uc_gov_staff ON 1=1 JOIN\r\n"
+ "(select count(1) as zz from up_lic_data) as zz_lic_data ON 1=1";
ps = xxxConnection.prepareStatement(sql);
rs = ps.executeQuery();
CountEntity ce = null;
if (rs.next()) {
ce = new CountEntity();
ce.setSx(rs.getInt("sx"));
ce.setBj(rs.getInt("bj"));
ce.setYh(rs.getInt("yh"));
ce.setZz(rs.getInt("zz"));
return ce;
} else {
return null;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
} public static void main(String[] args) {
QueryDataOfCharts instance = QueryDataOfCharts.getInstance();
CountEntity queryDbxxx = instance.queryDbxxx();
System.out.println(
"xxx " + queryDbxxx + "\n" + "========================================================="); } }

其实巴拉巴拉一大堆,我感觉上面这个大sql才是比较有意思的东西。其实好好看看挺好的,就是把一类的统计相加,然后最后输出到excel里面,还是比较有意思的。

第七步,就是将查询的数据量输出到excel里面就行了:

统计报表就有意思了,将统计的数据量放到list里面,然后将list放到map里面。这样一行的都放到list里面。不同行放到不同的list里面,这样循环遍历输出的时候就可以将不同的放到不同的行里面,完美的解决我的报表统计功能。

package com.fline.aic.excel;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.fline.aic.dao.QueryDataOfCharts;
import com.fline.aic.vo.CountEntity; /**
*
* @Description TODO
* @author biehl
* @Date 2018年9月21日 上午11:37:28
*
*/
public class WriteExcelForXSSF { private static WriteExcelForXSSF writeExcelForXSSF; private WriteExcelForXSSF() {
} public static WriteExcelForXSSF getInstance() {
if (writeExcelForXSSF == null) {
writeExcelForXSSF = new WriteExcelForXSSF();
}
return writeExcelForXSSF;
} /**
*
*/
public Map<Integer, List<Integer>> readDbAreaOfDabase() {
// Map集合
Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
// List集合
List<Integer> list = new ArrayList<Integer>();
// 获取到QueryDataOfCharts对象
QueryDataOfCharts instance = QueryDataOfCharts.getInstance();
// 查询到xxx的数据
CountEntity queryDbxxx = instance.queryDbxxx();
list.add(queryDbxxx.getSx());
list.add(queryDbxxx.getBj());
list.add(queryDbxxx.getZz());
list.add(queryDbxxx.getYh());
map.put(,list);
return map;
} public void writeDbAreaForXSSF() {
// 创建一个空的工作簿
Workbook workbook = new XSSFWorkbook();
// 创建一个sheet页
Sheet sheet = workbook.createSheet("xxxxxx报表"); // 合并单元格
/*
* sheet.addMergedRegion(new CellRangeAddress( 2,//第一行(从0开始) 2,//最后一行(从0开始)
* 0,//第一列(从0开始) 26 //最后一列(从0开始) ));
*/ // 创建一行,开始是0行,设置第2行
Row row = sheet.createRow();
// 创建一个单元格,第一列
// Cell cell = row.createCell(1);
// 第一行第一列设置值
// cell.setCellValue("资源共享服务中心数据汇聚统计表");
// row.createCell(0).setCellValue("资源共享服务中心数据汇聚统计表"); // 设置字体
Font font = workbook.createFont();
font.setFontHeightInPoints((short) );
font.setFontName("Courier New");
font.setBold(true); // 设置数字的字体
Font font2 = workbook.createFont();
font2.setFontHeightInPoints((short) );
font2.setFontName("Courier New");
font2.setBold(true); // 设置样式
CellStyle cs = workbook.createCellStyle();
cs.setFont(font); CellStyle cs2 = workbook.createCellStyle();
cs2.setFont(font2); // 将要设置字体的单元格进行设置
// 创建一个单元格,第一列
Cell cell = row.createCell();
// 第一行第一列设置值
cell.setCellValue("资源共享服务中心数据汇聚统计表");
cell.setCellStyle(cs); // 设置一行
Row row3 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell3 = row3.createCell();
// 为这一行这一列设置值
cell3.setCellValue("xxx");
cell3.setCellStyle(cs2); // 设置一行
Row row4 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell4 = row4.createCell();
// 为这一行这一列设置值
cell4.setCellValue("广东");
cell4.setCellStyle(cs2); // 设置一行
Row row5 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell5 = row5.createCell();
// 为这一行这一列设置值
cell5.setCellValue("江苏");
cell5.setCellStyle(cs2); // 设置一行
Row row6 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell6 = row6.createCell();
// 为这一行这一列设置值
cell6.setCellValue("贵州");
cell6.setCellStyle(cs2); // 设置一行
Row row7 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell7 = row7.createCell();
// 为这一行这一列设置值
cell7.setCellValue("山东");
cell7.setCellStyle(cs2); // 设置一行
Row row8 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell8 = row8.createCell();
// 为这一行这一列设置值
cell8.setCellValue("上海");
cell8.setCellStyle(cs2); // 设置一行
Row row9 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell9 = row9.createCell();
// 为这一行这一列设置值
cell9.setCellValue("安徽");
cell9.setCellStyle(cs2); // 设置一行
Row row10 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell10 = row10.createCell();
// 为这一行这一列设置值
cell10.setCellValue("四川");
cell10.setCellStyle(cs2); // 设置一行
Row row11 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell11 = row11.createCell();
// 为这一行这一列设置值
cell11.setCellValue("重庆");
cell11.setCellStyle(cs2); Row row12 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell12 = row12.createCell();
// 为这一行这一列设置值
cell12.setCellValue("脱敏后中间库");
cell12.setCellStyle(cs2); // 创建一列,第一列设置地方前置库名称
Cell cell13 = row12.createCell();
// 为这一行这一列设置值
cell13.setCellValue("汇聚数据区");
cell13.setCellStyle(cs2); // 创建一列,第一列设置地方前置库名称
Cell cell14 = row12.createCell();
// 为这一行这一列设置值
cell14.setCellValue("汇聚前置库");
cell14.setCellStyle(cs2); // 创建一列,第一列设置地方前置库名称
Cell cell15 = row12.createCell();
// 为这一行这一列设置值
cell15.setCellValue("应用前置库");
cell15.setCellStyle(cs2); // 创建一列,第一列设置地方前置库名称
Cell cell16 = row12.createCell();
// 为这一行这一列设置值
cell16.setCellValue("核心数据区");
cell16.setCellStyle(cs2); // 创建一列,第一列设置地方前置库名称
Cell cell17 = row12.createCell();
// 为这一行这一列设置值
cell17.setCellValue("共享前置库");
cell17.setCellStyle(cs2); //xxx,xxx,xxx,xxx
Row row13 = sheet.createRow();
// 创建一列,第一列设置地方前置库名称
Cell cell18 = row13.createCell();
// 为这一行这一列设置值
cell18.setCellValue("xxx");
cell18.setCellStyle(cs2); Cell cell19 = row13.createCell();
// 为这一行这一列设置值
cell19.setCellValue("xxx");
cell19.setCellStyle(cs2); Cell cell20 = row13.createCell();
// 为这一行这一列设置值
cell20.setCellValue("xxx");
cell20.setCellStyle(cs2); Cell cell21 = row13.createCell();
// 为这一行这一列设置值
cell21.setCellValue("xxx");
cell21.setCellStyle(cs2); Cell cell22 = row13.createCell();
// 为这一行这一列设置值
cell22.setCellValue("xxx");
cell22.setCellStyle(cs2); Cell cell23 = row13.createCell();
// 为这一行这一列设置值
cell23.setCellValue("xxx");
cell23.setCellStyle(cs2); Cell cell24 = row13.createCell();
// 为这一行这一列设置值
cell24.setCellValue("xxx");
cell24.setCellStyle(cs2); Cell cell25 = row13.createCell();
// 为这一行这一列设置值
cell25.setCellValue("xxx");
cell25.setCellStyle(cs2); Cell cell26 = row13.createCell();
// 为这一行这一列设置值
cell26.setCellValue("xxx");
cell26.setCellStyle(cs2); Cell cell27 = row13.createCell();
// 为这一行这一列设置值
cell27.setCellValue("xxx");
cell27.setCellStyle(cs2); Cell cell28 = row13.createCell();
// 为这一行这一列设置值
cell28.setCellValue("xxx");
cell28.setCellStyle(cs2); Cell cell29 = row13.createCell();
// 为这一行这一列设置值
cell29.setCellValue("xxx");
cell29.setCellStyle(cs2); Cell cell30 = row13.createCell();
// 为这一行这一列设置值
cell30.setCellValue("xxx");
cell30.setCellStyle(cs2); Cell cell31 = row13.createCell();
// 为这一行这一列设置值
cell31.setCellValue("xxx");
cell31.setCellStyle(cs2); Cell cell32 = row13.createCell();
// 为这一行这一列设置值
cell32.setCellValue("xxx");
cell32.setCellStyle(cs2); Cell cell33 = row13.createCell();
// 为这一行这一列设置值
cell33.setCellValue("xxx");
cell33.setCellStyle(cs2); Cell cell34 = row13.createCell();
// 为这一行这一列设置值
cell34.setCellValue("xxx");
cell34.setCellStyle(cs2); Cell cell35 = row13.createCell();
// 为这一行这一列设置值
cell35.setCellValue("xxx");
cell35.setCellStyle(cs2); Cell cell36 = row13.createCell();
// 为这一行这一列设置值
cell36.setCellValue("xxx");
cell36.setCellStyle(cs2); Cell cell37 = row13.createCell();
// 为这一行这一列设置值
cell37.setCellValue("xxx");
cell37.setCellStyle(cs2); int sxCount = ;// xxx
int bjCount = ;// xxx
int yhCount = ;// xxx
int zzCount = ;// xxx
int sumCount = ;// xxx,xxx,xxx,xxx总计
// 读取查询的xxx数据库的统计数据
WriteExcelForXSSF instance = WriteExcelForXSSF.getInstance();
Map<Integer, List<Integer>> readDbAreaOfDabase = instance.readDbAreaOfDabase();
for (int i = ; i < readDbAreaOfDabase.size(); i++) {
List<Integer> list = readDbAreaOfDabase.get(i);
// 设置一行
Row row2 = sheet.createRow(i + );
for (int j = ; j < list.size(); j++) {
// 创建一列,第二列设置数值
Cell cell2 = row2.createCell(j + );
// 获取这一行一这列的值
Integer value = list.get(j); // 为这一行这一列设置值
cell2.setCellValue(value);
cell2.setCellStyle(cs2);
//打印输出合计数量
//System.out.println(sxCount + "," + bjCount + "," + yhCount + "," + zzCount);
}
} // 创建输出流
try {
File file = new File("C:\\Users\\Aiyufei\\Desktop\\poi.xlsx");
if (file.exists()) {
file.delete();
} else {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fos = new FileOutputStream(file);
System.out.println(file.getName() + " ,excel文件已经成功创建.....");
try {
// 写入流中,创建此excel
workbook.write(fos);
} catch (IOException e) {
e.printStackTrace();
}
try {
// 关闭流
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println("开始时间:" + sdf.format(new Date()));
WriteExcelForXSSF instance = WriteExcelForXSSF.getInstance();
instance.writeDbAreaForXSSF();
System.out.println("结束时间:" + sdf.format(new Date()));
} }

待续.....

统计各个数据库的各个数据表的总数,然后写入到excel中的更多相关文章

  1. 孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数

    孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 不同类型 ...

  2. mysql之创建数据库,创建数据表

    写在前面 项目中用到mysql数据库,之前也没用过mysql,今天就学下mysql的常用的语法,发现跟sql server的语法极其相似.用起来还是蛮简单的. 一个例子 1.创建一个名为School的 ...

  3. android 一个SQLite数据库多个数据表的基本使用框架 (带demo)

    android 一个SQLite数据库多个数据表(带demo) 前言        demo演示        一.搭建        二.建立实体类        三.建立数据库操作类        ...

  4. MySQL 中的数据库名称、数据表名称、字段名称

    如何查询Oracle,Sql Server,MySQL 中的数据库名称.数据表名称.字段名称 分类: Database2012-09-24 22:16 7034人阅读 评论(0) 收藏 举报 数据库s ...

  5. wordpress数据库结构以及数据表之间的关系

    默认WordPress一共有以下11个表.这里加上了默认的表前缀 wp_ . wp_commentmeta:存储评论的元数据 wp_comments:存储评论 wp_links:存储友情链接(Blog ...

  6. ThinkPHP 学习笔记 ( 三 ) 数据库操作之数据表模型和基础模型 ( Model )

    //TP 恶补ing... 一.定义数据表模型 1.模型映射 要测试数据库是否正常连接,最直接的办法就是在当前控制器中实例化数据表,然后使用 dump 函数输出,查看数据库的链接状态.代码: publ ...

  7. ThinkPHP 数据库操作之数据表模型和基础模型 ( Model )

    一.定义数据表模型 1.模型映射 要测试数据库是否正常连接,最直接的办法就是在当前控制器中实例化数据表,然后使用 dump 函数输出,查看数据库的链接状态.代码: public function te ...

  8. MySQL:数据库名或者数据表名包含-

    [参考文章]:mysql数据库名称中包含短横线的对应方式 1. 现象 命令行下操作 名称包含 " - " 数据库或者数据表时,语句执行报错: 2. 解决方案: 使用 `` 字符(E ...

  9. 数据库MySQL--修改数据表

    创建数据库::create database 数据库名: 如果数据不存在则创建,存在不创建:Create database if not exists 数据库名 ; 删除数据库::drop datab ...

随机推荐

  1. DevExpress VCL 的 cxDBTreeList 的使用方法

    DevExpress VCL 的 cxDBTreeList 的使用方法:(假设控件名为: WBSTree) 1.控件WBSTree 通过绑定  DataSet 获取数据记录(Nodes),通过 Col ...

  2. 使用javascript调用com组件

    <html> <head> <title> 调用com组件的方法示例 </title> <script language="javasc ...

  3. 【转】线程join()方法的含义

    在很多情况下,主线程生成并启动了子线程,如果子线程里要进行大量的耗时运算,主线程往往将于子线程之前结束,但是如果主线程处理完其它事务后,需要用到子线程的处理结果,也就是主线程需要等待子线程执行完成之后 ...

  4. Android应用内嵌unity3d游戏项目

    在一个现有的Android项目中嵌入unity3d项目 1.将unity3d项目导出android工程 2.将第一步导出的Android工程中assets文件夹和libs文件夹下的所有内容复制到And ...

  5. NDK历史版本下载方法

    再比如说,你要下载Android NDK, Revision 8b ,只要下面链接就可以了: http://dl.google.com/android/ndk/android-ndk-r8b-Linu ...

  6. Linux下的进程结构

    Linux系统是一个多进程的系统,它的进程之间具有并行性.互不干扰等特点.也就是说,每个进程都是一个独立的运行单位,拥有各自的权利和责任.其中,各个进程都运行在独立的虚拟地址空间.因此,即使一个进程发 ...

  7. zabbix添加对centos系统cpu使用率百分比的监控

    cpu使用率key: system.cpu.util[] 在grafana现实的时候配置,单位选择percent(0-100),范围0-100

  8. gdb 调试程序步骤

    在程序a.c编译过程中加入调试信息: g++ -g -o a.debug a.c 启动gdb,在终端下输入:gdb 此时启动了gdb,在gdb中加载需要调试的程序,在终端输入命令: file a.de ...

  9. 【原创】Linux基础之chkconfig systemd

    CentOS6服务用chkconfig控制,CentOS7改为systemd控制 1 systemd systemd is a suite of basic building blocks for a ...

  10. ant自动编译打包android项目

    源代码及可执行文件下载地址:http://files.cnblogs.com/rainboy2010/antdemo.zip Android打包APK的流程如下:  下面我们开始尝试使用ant进行ap ...