USE `database`;

/*Table structure for table `post` */

DROP TABLE IF EXISTS `post`;

CREATE TABLE `post` (
`no` int(11) NOT NULL AUTO_INCREMENT COMMENT '序列号',
`attach` varchar(16) DEFAULT NULL COMMENT '隶属关系',
`areaNo` varchar(8) DEFAULT NULL COMMENT '地区编码',
`area` varchar(16) DEFAULT NULL COMMENT '地区',
`unitNo` varchar(8) DEFAULT NULL COMMENT '部门编码',
`unit` varchar(64) DEFAULT NULL COMMENT '部门',
`positionNo` varchar(8) DEFAULT NULL COMMENT '职位代码',
`position` varchar(64) DEFAULT NULL COMMENT '职位',
`positionDesc` varchar(1024) DEFAULT NULL COMMENT '职位简介',
`positionType` varchar(2) DEFAULT NULL COMMENT '职位类别',
`ratio` int(11) DEFAULT NULL COMMENT '开考比例',
`number` int(11) DEFAULT NULL COMMENT '人数',
`education` varchar(16) DEFAULT NULL COMMENT '学历',
`major` varchar(256) DEFAULT NULL COMMENT '专业',
`others` varchar(1024) DEFAULT NULL COMMENT '其他',
`city` varchar(16) DEFAULT NULL COMMENT '城市/垂直部门',
PRIMARY KEY (`no`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
package com.jsgwy.xls;

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class ParseXls
{
private static FileOutputStream out;
private static OutputStreamWriter outWriter;
private static BufferedWriter bufWrite; public static void main(String[] args) {
try {
out = new FileOutputStream("d:/post.sql");
outWriter = new OutputStreamWriter(out, "UTF-8");
bufWrite = new BufferedWriter(outWriter); POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("d:/test.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
for (int i = 0; i < 17; i++) {
HSSFSheet sheet = wb.getSheetAt(i);
dealSheet(sheet);
}
bufWrite.close();
outWriter.close();
out.close();
wb.close();
fs.close();
System.out.println("done!");
} catch (IOException e) {
e.printStackTrace();
}
} private static void dealSheet(HSSFSheet sheet) {
String sheetName = sheet.getSheetName();
int rowCounter = sheet.getLastRowNum();
for (int i = 3; i < rowCounter; i++) {
HSSFRow row = sheet.getRow(i);
int cellCounter = row.getLastCellNum();
StringBuilder sb = new StringBuilder();
String tablePrefix = "INSERT INTO `post`("
+ "`attach`,`areaNo`,`area`,`unitNo`,`unit`,"
+ "`positionNo`,`position`,`positionDesc`,`positionType`,"
+ "`ratio`,`number`,`education`,`major`,`others`,`city`) VALUES ('";
String attach = row.getCell(0).getStringCellValue().trim();
String areaNo = row.getCell(1).getStringCellValue().trim();
String area = row.getCell(2).getStringCellValue().trim();
String unitNo = row.getCell(3).getStringCellValue().trim();
String unit = row.getCell(4).getStringCellValue().trim();
String positionNo = row.getCell(5).getStringCellValue().trim();
String position = row.getCell(6).getStringCellValue().trim();
String positionDesc = row.getCell(7).getStringCellValue().trim();
String positionType = row.getCell(8).getStringCellValue().trim();
int ratio = (int)(row.getCell(9).getNumericCellValue());
int number = (int)(row.getCell(10).getNumericCellValue());
String education = row.getCell(11).getStringCellValue().trim();
String major = row.getCell(12).getStringCellValue().trim();
String others = "";
if (cellCounter > 13) {
others = row.getCell(13).getStringCellValue().trim();
}
others = others.replaceAll(";", "<br/>");
others = others.replaceAll(",", "<br/>");
String city = sheetName;
sb.append(tablePrefix).append(attach)
.append("','").append(areaNo)
.append("','").append(area)
.append("','").append(unitNo)
.append("','").append(unit)
.append("','").append(positionNo)
.append("','").append(position)
.append("','").append(positionDesc)
.append("','").append(positionType)
.append("',").append(ratio)
.append(",").append(number)
.append(",'").append(education)
.append("','").append(major)
.append("','").append(others)
.append("','").append(city)
.append("');");
try {
bufWrite.write(sb.toString() + "\r\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

江苏公务员职位表导入MySQL的更多相关文章

  1. 使用命令行将Excel数据表导入Mysql中的方法小结

    从Excel数据表导入MySQL,已经做过好几次了,但每次都会碰到各种问题:invalid utf8 character string, data too long, ...,浪费了不少时间 为了提高 ...

  2. 如何将EXCEL表导入MYSQL

            在平时的工作学习中,难免会遇到需要把EXCEL表中的数据导入到MYSQL中,比如要把EXCEL中的数据进行核对,或者要把测试用例导入到TestLink中.本人搜集相关的资料并加以实践总 ...

  3. Oracle表导入Mysql方法

    public void reportPerInfo(){ //每次导入清除之前数据 this.esEntPermitErrDao.updateObjectBySql("delete from ...

  4. sql 脚本 oracle scott 用户的四张表导入 mysql 中

    /* 要先删除emp表,不能先删除dept表,因为dept有一个外键关联emp表*/drop TABLE emp;drop TABLE dept; drop TABLE salgrade;drop T ...

  5. mysql单表导入数据,全量备份导入单表

    (1)“导出”表 导出表是在备份的prepare阶段进行的,因此,一旦完全备份完成,就可以在prepare过程中通过--export选项将某表导出了: innobackupex --apply-log ...

  6. Sqoop- sqoop将mysql数据表导入到hive报错

    sqoop将mysql数据表导入到hive报错 [root@ip---- lib]# sqoop import --connect jdbc:mysql://54.223.175.12:3308/gx ...

  7. 把execel表数据导入mysql数据库

    今天,是我来公司第二周的第一天. 作为新入职的实习生,目前还没适合我的实质项目工作,今天的学习任务是: 把execel表数据导入到mysql数据库,再练习下java操作JDBC. 先了解下execel ...

  8. PowerDesigner在修改表的字段Name的时Code不自动跟着变的处理方法以及导入Mysql数据库的表

    tools-> GeneralOptions-> Dialog:Operation   Modes: 去掉 NameToCodeMirroring 前面的√ 导入数据库中的表到PowerD ...

  9. 记录PHP post提交表单导入mysql中文乱码的问题

    记录记录PHP post提交表单导入mysql中文乱码的问题 关于乱码,这是个糟糕的问题!涉及到很多地方 解决思路:程序所涉及的环境字符集不一致导致 mysql出现乱码一般是mysql数据库内部的字符 ...

随机推荐

  1. PRId64的正确用法

    #include <inttypes.h> #include <stdint.h> #include <stdio.h> // g++ -g -o x x.cpp ...

  2. Spring源码解析 - AbstractBeanFactory 实现接口与父类分析

    我们先来看类图吧: 除了BeanFactory这一支的接口,AbstractBeanFactory主要实现了AliasRegistry和SingletonBeanRegistry接口. 这边主要提供了 ...

  3. (并查集)How Many Tables -- HDU --1213

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  4. (连通图 ) Redundant Paths --POJ --3177

    链接: http://poj.org/problem?id=3177 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#probl ...

  5. SpringMvc中controller之间的方法调用

    方法一, return new ModelAndView("redirect:"+新地址); 方法二, response.sendRedirect(新地址); return nul ...

  6. 20145234黄斐《java程序设计》第六周

    教材学习内容总结 第十章:输入与输出 InputStream与OutputStream 流(Stream)是对「输入输出」的抽象,注意「输入输出」是相对程序而言的 InputStream与Output ...

  7. 几个经典的数学库之一学习---VCGlib(3)

    Camera and shot abstraction for managing views 视图的定义,以及mesh的操作说明. Shot(镜头) and camera(相机) shot摄像结构以及 ...

  8. codevs 1160

    这道题还是和蛇形填数有关,因为要不停的去转圈圈去判断是否到了最中间的那个位置,所以用到了递归的思想. #include<stdio.h> int n,a[100][100]; void r ...

  9. hdu 4268 贪心+set lower_bound用法

    http://acm.hdu.edu.cn/showproblem.php?pid=4268 A想用手里的牌尽量多地覆盖掉B手中的牌.. 牌有h和w 问A手中的牌最多能覆盖B多少张牌 iterator ...

  10. 老刘 Yii2 源码学习笔记之 Module 类

    关系类图 从上图可以看出 Application 类继承了 Module,在框架中的是非常重要角色. 加载配置 public function setModules($modules) { forea ...