packagecom.java.activiti.util;importjava.io.FileOutputStream;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.ResultSetMetaData;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;importorg.apache.poi.ss.usermodel.Cell;importorg.apache.poi.ss.usermodel.Row;importorg.apache.poi.ss.usermodel.Sheet;importorg.apache.poi.ss.usermodel.Workbook;importcom.mysql.jdbc.Connection;importcom.mysql.jdbc.Statement;/*** Created by zhxn on 2018/10/30.*/
public classFromOneSheetToExcel1 {//TODO 需要将url\用户名\密码修改为自己的
public final static String url = "jdbc:mysql://localhost:3306/subway"; //数据库URL
public final static String user = "root"; //数据库用户名
public final static String password = "123456"; //数据库密码//把数据库单张表信息导入到Excel表中
public static void main(String[] args) throwsException {//架子啊数据库驱动
Class.forName("com.mysql.jdbc.Driver");//连接数据库//Connection con = (Connection) DriverManager.getConnection(url, user,//password);// //创建Excel表。//Workbook book = new HSSFWorkbook();//
//String Table_Name = "result";//
//Sheet sheet = book.createSheet(Table_Name);//
//Statement st = (Statement) con.createStatement();// //创建sql语句,对team进行查询所有数据//String sql = "select t.id,t.para_org_leaderships_id,t.PAPER_ID,t.OBJ_RESULT,t.SUB_RESULT,t.TOTAL_RESULT from"//+ " (select id,para_org_leaderships_id,PAPER_ID,OBJ_RESULT,SUB_RESULT,TOTAL_RESULT from "//+ ""+Table_Name+" union select '成绩编号','组织架构参数表编号','试卷编号','客观题成绩','主观题成绩','总成绩') "//+ "t order by t.id desc" ;//ResultSet rs = st.executeQuery(sql);// //设置表头信息(写入Excel左上角是从(0,0)开始的)//Row row1 = sheet.createRow(0);//ResultSetMetaData rsmd = rs.getMetaData();//int colnum = rsmd.getColumnCount();//
// //设置表格信息//int idx = 0;//while (rs.next()) {// //行//Row row = sheet.createRow(idx++);//for (int i = 1; i <= colnum; i++) {//String str="";//str = rs.getString(i);// //单元格//Cell cell = row.createCell(i-1);// //写入数据//cell.setCellValue(str);//}//}// //保存//book.write(new FileOutputStream("D://" + Table_Name + ".xls"));
}
}