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

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

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

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

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

依赖如下所示:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.</modelVersion>
  4. <groupId>com.charts</groupId>
  5. <artifactId>com.fline.aic.charts</artifactId>
  6. <packaging>war</packaging>
  7. <version>0.0.-SNAPSHOT</version>
  8. <name>com.fline.aic.charts Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10.  
  11. <dependencies>
  12. <dependency>
  13. <groupId>junit</groupId>
  14. <artifactId>junit</artifactId>
  15. <version>3.8.</version>
  16. <scope>test</scope>
  17. </dependency>
  18. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
  19. <dependency>
  20. <groupId>org.apache.poi</groupId>
  21. <artifactId>poi-ooxml</artifactId>
  22. <version>3.9</version>
  23. </dependency>
  24. <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  25. <dependency>
  26. <groupId>mysql</groupId>
  27. <artifactId>mysql-connector-java</artifactId>
  28. <version>5.1.</version>
  29. </dependency>
  30. <!-- https://mvnrepository.com/artifact/com.pivotal/greenplum-jdbc -->
  31. <!-- <dependency>
  32. <groupId>com.pivotal</groupId>
  33. <artifactId>greenplum-jdbc</artifactId>
  34. <version>5.1.</version>
  35. </dependency> -->
  36. <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
  37. <dependency>
  38. <groupId>org.postgresql</groupId>
  39. <artifactId>postgresql</artifactId>
  40. <version>42.1.</version>
  41. </dependency>
  42. <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
  43. <dependency>
  44. <groupId>com.alibaba</groupId>
  45. <artifactId>fastjson</artifactId>
  46. <version>1.2.</version>
  47. </dependency>
  48. <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
  49. <dependency>
  50. <groupId>commons-beanutils</groupId>
  51. <artifactId>commons-beanutils</artifactId>
  52. <version>1.9.</version>
  53. </dependency>
  54. <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
  55. <dependency>
  56. <groupId>org.apache.commons</groupId>
  57. <artifactId>commons-lang3</artifactId>
  58. <version>3.4</version>
  59. </dependency>
  60. <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
  61. <dependency>
  62. <groupId>commons-logging</groupId>
  63. <artifactId>commons-logging</artifactId>
  64. <version>1.1.</version>
  65. </dependency>
  66. <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
  67. <dependency>
  68. <groupId>commons-collections</groupId>
  69. <artifactId>commons-collections</artifactId>
  70. <version>3.2.</version>
  71. </dependency>
  72. <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
  73. <dependency>
  74. <groupId>com.mchange</groupId>
  75. <artifactId>c3p0</artifactId>
  76. <version>0.9.5.2</version>
  77. </dependency>
  78. <!-- -->
  79. <dependency>
  80. <groupId>org.apache.poi</groupId>
  81. <artifactId>poi-ooxml</artifactId>
  82. <version>3.15</version>
  83. </dependency>
  84. <!-- https://mvnrepository.com/artifact/org.json/json -->
  85. <dependency>
  86. <groupId>org.json</groupId>
  87. <artifactId>json</artifactId>
  88. <version></version>
  89. </dependency>
  90.  
  91. </dependencies>
  92. <build>
  93. <finalName>com.fline.aic.charts</finalName>
  94. </build>
  95.  
  96. </project>

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

形如如下所示:

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

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

  1. package com.fline.aic.utils;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.ResourceBundle;
  9.  
  10. /**
  11. *
  12. * @Description TODO
  13. * @author biehl
  14. * @Date 2018年9月21日 上午9:32:04
  15. *
  16. */
  17. public class JdbcUtils {
  18.  
  19. //
  20. private static String db_xxx_driver;
  21. private static String db_xxx_url;
  22. private static String db_xxx_user;
  23. private static String db_xxx_password;
  24.  
  25. //
  26. static {
  27. db_xxx_driver = ResourceBundle.getBundle("db").getString("db_xxx_driver");
  28. db_xxx_url = ResourceBundle.getBundle("db").getString("db_xxx_url");
  29. db_xxx_user = ResourceBundle.getBundle("db").getString("db_xxx_user");
  30. db_xxx_password = ResourceBundle.getBundle("db").getString("db_xxx_password");
  31. }
  32.  
  33. /**
  34. * 1
  35. * @return
  36. * @throws ClassNotFoundException
  37. * @throws SQLException
  38. */
  39. public static Connection getxxxConnection() throws ClassNotFoundException, SQLException {
  40. // 加载数据库驱动
  41. Class.forName(db_xxx_driver);
  42. // System.out.println("测试加载数据库成功");
  43. Connection con = DriverManager.getConnection(db_xxx_url, db_xxx_user, db_xxx_password);
  44. // System.out.println("测试数据库链接成功");
  45. return con;
  46. }
  47.  
  48. /**
  49. *
  50. * @param con
  51. * @param ps
  52. * @param rs
  53. */
  54. public static void closeConnection(Connection con, PreparedStatement ps, ResultSet rs) {
  55. if (rs != null) {// 关闭资源,避免出现异常
  56. try {
  57. rs.close();
  58. } catch (SQLException e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. if (ps != null) {
  63. try {
  64. ps.close();
  65. } catch (SQLException e) {
  66. e.printStackTrace();
  67. }
  68. }
  69. if (con != null) {
  70. try {
  71. con.close();
  72. } catch (SQLException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76. }
  77.  
  78. public static void main(String[] args) {
  79. try {
  80. JdbcUtils.getxxxConnection();
  81. System.out.println("xxx前置库连接成功.....");
  82. System.out.println("=======================================");
  83.  
  84. } catch (ClassNotFoundException e) {
  85. e.printStackTrace();
  86. } catch (SQLException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90.  
  91. }

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

  1. package com.fline.aic.vo;
  2.  
  3. import java.io.Serializable;
  4.  
  5. /**
  6. *
  7. * @Description TODO
  8. * @author biehl
  9. * @Date 2018年9月21日 上午10:50:47
  10. *
  11. */
  12. public class CountEntity implements Serializable {
  13.  
  14. /**
  15. *
  16. */
  17. private static final long serialVersionUID = 1L;
  18. private Integer sx;// xx
  19. private Integer bj;// xx
  20. private Integer yh;// xx
  21. private Integer zz;// xx
  22.  
  23. public Integer getSx() {
  24. return sx;
  25. }
  26.  
  27. public void setSx(Integer sx) {
  28. this.sx = sx;
  29. }
  30.  
  31. public Integer getBj() {
  32. return bj;
  33. }
  34.  
  35. public void setBj(Integer bj) {
  36. this.bj = bj;
  37. }
  38.  
  39. public Integer getYh() {
  40. return yh;
  41. }
  42.  
  43. public void setYh(Integer yh) {
  44. this.yh = yh;
  45. }
  46.  
  47. public Integer getZz() {
  48. return zz;
  49. }
  50.  
  51. public void setZz(Integer zz) {
  52. this.zz = zz;
  53. }
  54.  
  55. public CountEntity(Integer sx, Integer bj, Integer yh, Integer zz) {
  56. super();
  57. this.sx = sx;
  58. this.bj = bj;
  59. this.yh = yh;
  60. this.zz = zz;
  61. }
  62.  
  63. public CountEntity() {
  64. super();
  65. }
  66.  
  67. @Override
  68. public String toString() {
  69. return "CountEntity [sx=" + sx + ", bj=" + bj + ", yh=" + yh + ", zz=" + zz + "]";
  70. }
  71.  
  72. }

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

  1. package com.fline.aic.dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import com.fline.aic.utils.JdbcUtils;
  9. import com.fline.aic.vo.CountEntity;
  10.  
  11. /**
  12. *
  13. * @Description TODO
  14. * @author biehl
  15. * @Date 2018年9月21日 上午10:33:03
  16. *
  17. */
  18. public class QueryDataOfCharts {
  19.  
  20. private static QueryDataOfCharts queryDataOfCharts;
  21.  
  22. private QueryDataOfCharts() {
  23. }
  24.  
  25. public static QueryDataOfCharts getInstance() {
  26. if (queryDataOfCharts == null) {
  27. queryDataOfCharts = new QueryDataOfCharts();
  28. }
  29. return queryDataOfCharts;
  30. }
  31.  
  32. public Connection con = null;
  33. public PreparedStatement ps = null;
  34. public ResultSet rs = null;
  35.  
  36. /**
  37. * 1
  38. *
  39. * @return
  40. */
  41. public CountEntity queryDbxxx() {
  42. try {
  43. Connection xxxConnection = JdbcUtils.getxxxConnection();
  44. String sql = "select\r\n"
  45. + " (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"
  46. + "from \r\n"
  47. + "(select count(1) as sx from up_task_directory) as sx_directory JOIN\r\n"
  48. + "(select count(1) as sx from up_task_general_basic) as sx_general_basic ON 1=1 JOIN\r\n"
  49. + "(select count(1) as sx from up_task_general_extend) as sx_general_extend ON 1=1 JOIN\r\n"
  50. + "(select count(1) as sx from up_task_general_material) as sx_general_material ON 1=1 JOIN\r\n"
  51. + "(select count(1) as sx from up_task_general_fee_project) as sx_general_fee_project ON 1=1 JOIN\r\n"
  52. + "(select count(1) as sx from up_task_general_questions) as sx_general_questions ON 1=1 JOIN\r\n"
  53. + "(select count(1) as sx from up_task_punish_basic) as sx_punish_basic ON 1=1 JOIN\r\n"
  54. + "(select count(1) as sx from up_task_punish_questions) as sx_punish_questions ON 1=1 JOIN\r\n"
  55. + "(select count(1) as sx from up_task_handle_basic) as sx_handle_basic ON 1=1 JOIN\r\n"
  56. + "(select count(1) as sx from up_task_handle_material) as sx_handle_material ON 1=1 JOIN\r\n"
  57. + "(select count(1) as sx from up_task_handle_questions) as sx_handle_questions ON 1=1 JOIN\r\n"
  58. + "(select count(1) as sx from up_task_public_basic) as sx_public_basic ON 1=1 JOIN\r\n"
  59. + "(select count(1) as sx from up_task_public_extend) as sx_public_extend ON 1=1 JOIN\r\n"
  60. + "(select count(1) as sx from up_task_public_material) as sx_public_material ON 1=1 JOIN\r\n"
  61. + "(select count(1) as sx from up_task_public_fee_project) as sx_public_fee_project ON 1=1 JOIN\r\n"
  62. + "(select count(1) as sx from up_task_public_questions) as sx_public_questions ON 1=1 JOIN\r\n"
  63. + "(select count(1) as sx from up_task_check_basic) as sx_check_basic ON 1=1 JOIN\r\n"
  64. + "(select count(1) as sx from up_task_check_questions) as sx_check_questions ON 1=1 JOIN\r\n"
  65. + "(select count(1) as sx from up_zone_organization) as sx_zone_organization ON 1=1 JOIN\r\n"
  66. + "(select count(1) as bj from up_pro_accept) as bj_pro_accept ON 1=1 JOIN\r\n"
  67. + "(select count(1) as bj from up_pro_process) as bj_pro_process ON 1=1 JOIN\r\n"
  68. + "(select count(1) as bj from up_pro_result) as bj_pro_result ON 1=1 JOIN\r\n"
  69. + "(select count(1) as bj from up_pro_specialprocedure) as bj_pro_specialprocedure ON 1=1 JOIN\r\n"
  70. + "(select count(1) as bj from up_pro_material) as bj_pro_material ON 1=1 JOIN \r\n"
  71. + "(select count(1) as yh from up_uc_province_user) as yh_uc_province_user ON 1=1 JOIN\r\n"
  72. + "(select count(1) as yh from up_uc_corporator_identity) as yh_uc_corporator_identity ON 1=1 JOIN\r\n"
  73. + "(select count(1) as yh from up_uc_corporator_account) as yh_uc_corporator_account ON 1=1 JOIN\r\n"
  74. + "(select count(1) as yh from up_uc_info_enterprise) as yh_uc_info_enterprise ON 1=1 JOIN\r\n"
  75. + "(select count(1) as yh from up_uc_info_association) as yh_uc_info_association ON 1=1 JOIN \r\n"
  76. + "(select count(1) as yh from up_uc_info_central_dept) as yh_uc_info_central_dept ON 1=1 JOIN\r\n"
  77. + "(select count(1) as yh from up_uc_gov_org) as yh_uc_gov_org ON 1=1 JOIN\r\n"
  78. + "(select count(1) as yh from up_uc_gov_region) as yh_uc_gov_region ON 1=1 JOIN\r\n"
  79. + "(select count(1) as yh from up_uc_gov_staff) as yh_uc_gov_staff ON 1=1 JOIN\r\n"
  80. + "(select count(1) as zz from up_lic_data) as zz_lic_data ON 1=1";
  81. ps = xxxConnection.prepareStatement(sql);
  82. rs = ps.executeQuery();
  83. CountEntity ce = null;
  84. if (rs.next()) {
  85. ce = new CountEntity();
  86. ce.setSx(rs.getInt("sx"));
  87. ce.setBj(rs.getInt("bj"));
  88. ce.setYh(rs.getInt("yh"));
  89. ce.setZz(rs.getInt("zz"));
  90. return ce;
  91. } else {
  92. return null;
  93. }
  94. } catch (ClassNotFoundException e) {
  95. e.printStackTrace();
  96. } catch (SQLException e) {
  97. e.printStackTrace();
  98. }
  99. return null;
  100. }
  101.  
  102. public static void main(String[] args) {
  103. QueryDataOfCharts instance = QueryDataOfCharts.getInstance();
  104. CountEntity queryDbxxx = instance.queryDbxxx();
  105. System.out.println(
  106. "xxx " + queryDbxxx + "\n" + "=========================================================");
  107.  
  108. }
  109.  
  110. }

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

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

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

  1. package com.fline.aic.excel;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13.  
  14. import org.apache.poi.ss.usermodel.Cell;
  15. import org.apache.poi.ss.usermodel.CellStyle;
  16. import org.apache.poi.ss.usermodel.Font;
  17. import org.apache.poi.ss.usermodel.Row;
  18. import org.apache.poi.ss.usermodel.Sheet;
  19. import org.apache.poi.ss.usermodel.Workbook;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21.  
  22. import com.fline.aic.dao.QueryDataOfCharts;
  23. import com.fline.aic.vo.CountEntity;
  24.  
  25. /**
  26. *
  27. * @Description TODO
  28. * @author biehl
  29. * @Date 2018年9月21日 上午11:37:28
  30. *
  31. */
  32. public class WriteExcelForXSSF {
  33.  
  34. private static WriteExcelForXSSF writeExcelForXSSF;
  35.  
  36. private WriteExcelForXSSF() {
  37. }
  38.  
  39. public static WriteExcelForXSSF getInstance() {
  40. if (writeExcelForXSSF == null) {
  41. writeExcelForXSSF = new WriteExcelForXSSF();
  42. }
  43. return writeExcelForXSSF;
  44. }
  45.  
  46. /**
  47. *
  48. */
  49. public Map<Integer, List<Integer>> readDbAreaOfDabase() {
  50. // Map集合
  51. Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
  52. // List集合
  53. List<Integer> list = new ArrayList<Integer>();
  54. // 获取到QueryDataOfCharts对象
  55. QueryDataOfCharts instance = QueryDataOfCharts.getInstance();
  56. // 查询到xxx的数据
  57. CountEntity queryDbxxx = instance.queryDbxxx();
  58. list.add(queryDbxxx.getSx());
  59. list.add(queryDbxxx.getBj());
  60. list.add(queryDbxxx.getZz());
  61. list.add(queryDbxxx.getYh());
  62. map.put(,list);
  63. return map;
  64. }
  65.  
  66. public void writeDbAreaForXSSF() {
  67. // 创建一个空的工作簿
  68. Workbook workbook = new XSSFWorkbook();
  69. // 创建一个sheet页
  70. Sheet sheet = workbook.createSheet("xxxxxx报表");
  71.  
  72. // 合并单元格
  73. /*
  74. * sheet.addMergedRegion(new CellRangeAddress( 2,//第一行(从0开始) 2,//最后一行(从0开始)
  75. * 0,//第一列(从0开始) 26 //最后一列(从0开始) ));
  76. */
  77.  
  78. // 创建一行,开始是0行,设置第2行
  79. Row row = sheet.createRow();
  80. // 创建一个单元格,第一列
  81. // Cell cell = row.createCell(1);
  82. // 第一行第一列设置值
  83. // cell.setCellValue("资源共享服务中心数据汇聚统计表");
  84. // row.createCell(0).setCellValue("资源共享服务中心数据汇聚统计表");
  85.  
  86. // 设置字体
  87. Font font = workbook.createFont();
  88. font.setFontHeightInPoints((short) );
  89. font.setFontName("Courier New");
  90. font.setBold(true);
  91.  
  92. // 设置数字的字体
  93. Font font2 = workbook.createFont();
  94. font2.setFontHeightInPoints((short) );
  95. font2.setFontName("Courier New");
  96. font2.setBold(true);
  97.  
  98. // 设置样式
  99. CellStyle cs = workbook.createCellStyle();
  100. cs.setFont(font);
  101.  
  102. CellStyle cs2 = workbook.createCellStyle();
  103. cs2.setFont(font2);
  104.  
  105. // 将要设置字体的单元格进行设置
  106. // 创建一个单元格,第一列
  107. Cell cell = row.createCell();
  108. // 第一行第一列设置值
  109. cell.setCellValue("资源共享服务中心数据汇聚统计表");
  110. cell.setCellStyle(cs);
  111.  
  112. // 设置一行
  113. Row row3 = sheet.createRow();
  114. // 创建一列,第一列设置地方前置库名称
  115. Cell cell3 = row3.createCell();
  116. // 为这一行这一列设置值
  117. cell3.setCellValue("xxx");
  118. cell3.setCellStyle(cs2);
  119.  
  120. // 设置一行
  121. Row row4 = sheet.createRow();
  122. // 创建一列,第一列设置地方前置库名称
  123. Cell cell4 = row4.createCell();
  124. // 为这一行这一列设置值
  125. cell4.setCellValue("广东");
  126. cell4.setCellStyle(cs2);
  127.  
  128. // 设置一行
  129. Row row5 = sheet.createRow();
  130. // 创建一列,第一列设置地方前置库名称
  131. Cell cell5 = row5.createCell();
  132. // 为这一行这一列设置值
  133. cell5.setCellValue("江苏");
  134. cell5.setCellStyle(cs2);
  135.  
  136. // 设置一行
  137. Row row6 = sheet.createRow();
  138. // 创建一列,第一列设置地方前置库名称
  139. Cell cell6 = row6.createCell();
  140. // 为这一行这一列设置值
  141. cell6.setCellValue("贵州");
  142. cell6.setCellStyle(cs2);
  143.  
  144. // 设置一行
  145. Row row7 = sheet.createRow();
  146. // 创建一列,第一列设置地方前置库名称
  147. Cell cell7 = row7.createCell();
  148. // 为这一行这一列设置值
  149. cell7.setCellValue("山东");
  150. cell7.setCellStyle(cs2);
  151.  
  152. // 设置一行
  153. Row row8 = sheet.createRow();
  154. // 创建一列,第一列设置地方前置库名称
  155. Cell cell8 = row8.createCell();
  156. // 为这一行这一列设置值
  157. cell8.setCellValue("上海");
  158. cell8.setCellStyle(cs2);
  159.  
  160. // 设置一行
  161. Row row9 = sheet.createRow();
  162. // 创建一列,第一列设置地方前置库名称
  163. Cell cell9 = row9.createCell();
  164. // 为这一行这一列设置值
  165. cell9.setCellValue("安徽");
  166. cell9.setCellStyle(cs2);
  167.  
  168. // 设置一行
  169. Row row10 = sheet.createRow();
  170. // 创建一列,第一列设置地方前置库名称
  171. Cell cell10 = row10.createCell();
  172. // 为这一行这一列设置值
  173. cell10.setCellValue("四川");
  174. cell10.setCellStyle(cs2);
  175.  
  176. // 设置一行
  177. Row row11 = sheet.createRow();
  178. // 创建一列,第一列设置地方前置库名称
  179. Cell cell11 = row11.createCell();
  180. // 为这一行这一列设置值
  181. cell11.setCellValue("重庆");
  182. cell11.setCellStyle(cs2);
  183.  
  184. Row row12 = sheet.createRow();
  185. // 创建一列,第一列设置地方前置库名称
  186. Cell cell12 = row12.createCell();
  187. // 为这一行这一列设置值
  188. cell12.setCellValue("脱敏后中间库");
  189. cell12.setCellStyle(cs2);
  190.  
  191. // 创建一列,第一列设置地方前置库名称
  192. Cell cell13 = row12.createCell();
  193. // 为这一行这一列设置值
  194. cell13.setCellValue("汇聚数据区");
  195. cell13.setCellStyle(cs2);
  196.  
  197. // 创建一列,第一列设置地方前置库名称
  198. Cell cell14 = row12.createCell();
  199. // 为这一行这一列设置值
  200. cell14.setCellValue("汇聚前置库");
  201. cell14.setCellStyle(cs2);
  202.  
  203. // 创建一列,第一列设置地方前置库名称
  204. Cell cell15 = row12.createCell();
  205. // 为这一行这一列设置值
  206. cell15.setCellValue("应用前置库");
  207. cell15.setCellStyle(cs2);
  208.  
  209. // 创建一列,第一列设置地方前置库名称
  210. Cell cell16 = row12.createCell();
  211. // 为这一行这一列设置值
  212. cell16.setCellValue("核心数据区");
  213. cell16.setCellStyle(cs2);
  214.  
  215. // 创建一列,第一列设置地方前置库名称
  216. Cell cell17 = row12.createCell();
  217. // 为这一行这一列设置值
  218. cell17.setCellValue("共享前置库");
  219. cell17.setCellStyle(cs2);
  220.  
  221. //xxx,xxx,xxx,xxx
  222. Row row13 = sheet.createRow();
  223. // 创建一列,第一列设置地方前置库名称
  224. Cell cell18 = row13.createCell();
  225. // 为这一行这一列设置值
  226. cell18.setCellValue("xxx");
  227. cell18.setCellStyle(cs2);
  228.  
  229. Cell cell19 = row13.createCell();
  230. // 为这一行这一列设置值
  231. cell19.setCellValue("xxx");
  232. cell19.setCellStyle(cs2);
  233.  
  234. Cell cell20 = row13.createCell();
  235. // 为这一行这一列设置值
  236. cell20.setCellValue("xxx");
  237. cell20.setCellStyle(cs2);
  238.  
  239. Cell cell21 = row13.createCell();
  240. // 为这一行这一列设置值
  241. cell21.setCellValue("xxx");
  242. cell21.setCellStyle(cs2);
  243.  
  244. Cell cell22 = row13.createCell();
  245. // 为这一行这一列设置值
  246. cell22.setCellValue("xxx");
  247. cell22.setCellStyle(cs2);
  248.  
  249. Cell cell23 = row13.createCell();
  250. // 为这一行这一列设置值
  251. cell23.setCellValue("xxx");
  252. cell23.setCellStyle(cs2);
  253.  
  254. Cell cell24 = row13.createCell();
  255. // 为这一行这一列设置值
  256. cell24.setCellValue("xxx");
  257. cell24.setCellStyle(cs2);
  258.  
  259. Cell cell25 = row13.createCell();
  260. // 为这一行这一列设置值
  261. cell25.setCellValue("xxx");
  262. cell25.setCellStyle(cs2);
  263.  
  264. Cell cell26 = row13.createCell();
  265. // 为这一行这一列设置值
  266. cell26.setCellValue("xxx");
  267. cell26.setCellStyle(cs2);
  268.  
  269. Cell cell27 = row13.createCell();
  270. // 为这一行这一列设置值
  271. cell27.setCellValue("xxx");
  272. cell27.setCellStyle(cs2);
  273.  
  274. Cell cell28 = row13.createCell();
  275. // 为这一行这一列设置值
  276. cell28.setCellValue("xxx");
  277. cell28.setCellStyle(cs2);
  278.  
  279. Cell cell29 = row13.createCell();
  280. // 为这一行这一列设置值
  281. cell29.setCellValue("xxx");
  282. cell29.setCellStyle(cs2);
  283.  
  284. Cell cell30 = row13.createCell();
  285. // 为这一行这一列设置值
  286. cell30.setCellValue("xxx");
  287. cell30.setCellStyle(cs2);
  288.  
  289. Cell cell31 = row13.createCell();
  290. // 为这一行这一列设置值
  291. cell31.setCellValue("xxx");
  292. cell31.setCellStyle(cs2);
  293.  
  294. Cell cell32 = row13.createCell();
  295. // 为这一行这一列设置值
  296. cell32.setCellValue("xxx");
  297. cell32.setCellStyle(cs2);
  298.  
  299. Cell cell33 = row13.createCell();
  300. // 为这一行这一列设置值
  301. cell33.setCellValue("xxx");
  302. cell33.setCellStyle(cs2);
  303.  
  304. Cell cell34 = row13.createCell();
  305. // 为这一行这一列设置值
  306. cell34.setCellValue("xxx");
  307. cell34.setCellStyle(cs2);
  308.  
  309. Cell cell35 = row13.createCell();
  310. // 为这一行这一列设置值
  311. cell35.setCellValue("xxx");
  312. cell35.setCellStyle(cs2);
  313.  
  314. Cell cell36 = row13.createCell();
  315. // 为这一行这一列设置值
  316. cell36.setCellValue("xxx");
  317. cell36.setCellStyle(cs2);
  318.  
  319. Cell cell37 = row13.createCell();
  320. // 为这一行这一列设置值
  321. cell37.setCellValue("xxx");
  322. cell37.setCellStyle(cs2);
  323.  
  324. int sxCount = ;// xxx
  325. int bjCount = ;// xxx
  326. int yhCount = ;// xxx
  327. int zzCount = ;// xxx
  328. int sumCount = ;// xxx,xxx,xxx,xxx总计
  329. // 读取查询的xxx数据库的统计数据
  330. WriteExcelForXSSF instance = WriteExcelForXSSF.getInstance();
  331. Map<Integer, List<Integer>> readDbAreaOfDabase = instance.readDbAreaOfDabase();
  332. for (int i = ; i < readDbAreaOfDabase.size(); i++) {
  333. List<Integer> list = readDbAreaOfDabase.get(i);
  334. // 设置一行
  335. Row row2 = sheet.createRow(i + );
  336. for (int j = ; j < list.size(); j++) {
  337. // 创建一列,第二列设置数值
  338. Cell cell2 = row2.createCell(j + );
  339. // 获取这一行一这列的值
  340. Integer value = list.get(j);
  341.  
  342. // 为这一行这一列设置值
  343. cell2.setCellValue(value);
  344. cell2.setCellStyle(cs2);
  345. //打印输出合计数量
  346. //System.out.println(sxCount + "," + bjCount + "," + yhCount + "," + zzCount);
  347. }
  348. }
  349.  
  350. // 创建输出流
  351. try {
  352. File file = new File("C:\\Users\\Aiyufei\\Desktop\\poi.xlsx");
  353. if (file.exists()) {
  354. file.delete();
  355. } else {
  356. try {
  357. file.createNewFile();
  358. } catch (IOException e) {
  359. e.printStackTrace();
  360. }
  361. }
  362. FileOutputStream fos = new FileOutputStream(file);
  363. System.out.println(file.getName() + " ,excel文件已经成功创建.....");
  364. try {
  365. // 写入流中,创建此excel
  366. workbook.write(fos);
  367. } catch (IOException e) {
  368. e.printStackTrace();
  369. }
  370. try {
  371. // 关闭流
  372. fos.close();
  373. } catch (IOException e) {
  374. e.printStackTrace();
  375. }
  376. } catch (FileNotFoundException e) {
  377. // TODO Auto-generated catch block
  378. e.printStackTrace();
  379. }
  380. }
  381.  
  382. public static void main(String[] args) {
  383. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  384. System.out.println("开始时间:" + sdf.format(new Date()));
  385. WriteExcelForXSSF instance = WriteExcelForXSSF.getInstance();
  386. instance.writeDbAreaForXSSF();
  387. System.out.println("结束时间:" + sdf.format(new Date()));
  388. }
  389.  
  390. }

待续.....

统计各个数据库的各个数据表的总数,然后写入到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. RabbitMQ与SpringBoot整合

    RabbitMQ  SpringBoot  一.RabbitMQ的介绍 二.Direct模式 三.Topic转发模式 四.Fanout Exchange形式 原文地址: https://www.cnb ...

  2. Python3-lamba表达式、zip函数

    lambda表达式 学习条件运算时,对于简单的 if else 语句,可以使用三元运算来表示,即: # 普通条件语句 == : name = 'wupeiqi' else: name = 'alex' ...

  3. Ubuntu的内核转储工具【转】

    转自:http://www.cnblogs.com/wwang/archive/2010/11/19/1881304.html 在我的上一篇博文<Linux内核的Oops>的最后介绍到一个 ...

  4. Python3学习笔记30-datetime模块

    datetime是Python处理日期和时间的标准库 获取当前的日期和时间 from datetime import datetime now = datetime.now() print(now) ...

  5. MFC不可不会

    这些可能会很抽象,你既然学MFC,给你几个不可少的技术点 1.Dynamic Creation2.Runtime Type Imformation3.Persistence4.Message Mapp ...

  6. ACM Computer Factory POJ - 3436 网络流拆点+路径还原

    http://poj.org/problem?id=3436 每台电脑有$p$个组成部分,有$n$个工厂加工电脑. 每个工厂对于进入工厂的半成品的每个组成部分都有要求,由$p$个数字描述,0代表这个部 ...

  7. Mudo C++网络库第三章学习笔记

    多线程服务器的适用场合与常用编程模型 进程间通信与线程同步; 以最简单规范的方式开发功能正确.线程安全的多线程程序; 多线程服务器是指运行在linux操作系统上的独占式网络应用程序; 不考虑分布式存储 ...

  8. Cinder模块学习

    理解 Cinder 架构 - 每天5分钟玩转 OpenStack(45)   从本节开始我们学习 OpenStack 的 Block Storage Service,Cinder 理解 Block S ...

  9. Light OJ 1214

    简单大数模拟题: #include<bits/stdc++.h> using namespace std; typedef long long ll; string Num; vector ...

  10. Android调试adb devices找不到设备【转】

    adb驱动已经安装成功,但是adb devices却无法找到设备,USB大容量存储也是正常: 以前如果出现此种情况,我能想到的原因如下: 1.杀毒软件问题(关闭MacAfee) 2.驱动安装有误,重新 ...