加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java的poi技术读取Excel数据到MySQL

发布时间:2020-12-14 06:30:36 所属栏目:Java 来源:网络整理
导读:这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中。 你也可以在 : ? 了解到写入Excel的方法信息 使用JXL技术可以在 : `id` ( ) `no` ( ) `name` ( ) `age` ( ) `score` ) ENGINE InnoDB CHARSET utf8; main(String[] args) SaveData2DB

这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中。

你也可以在 :?了解到写入Excel的方法信息

使用JXL技术可以在 :

`id` () `no` () `name` () `age` () `score` ) ENGINEInnoDB CHARSETutf8;

main(String[] args) SaveData2DB saveData2DB = System.out.println("end" }

String DRIVER = "com.mysql.jdbc.Driver" String DB_NAME = "test" String USERNAME = "root" String PASSWORD = "root" String IP = "192.168.1.103" String PORT = "3306" String URL = "jdbc:mysql://" + IP + ":" + PORT + "/" + String EXCEL_PATH = "lib/student_info.xls" String INSERT_STUDENT_SQL = "insert into student_info(no,name,age,score) values(?,?,?)" String UPDATE_STUDENT_SQL = "update student_info set no = ?,name = ?,age= ?,score = ? where id = ? " String SELECT_STUDENT_ALL_SQL = "select id,no,score from student_info" String SELECT_STUDENT_SQL = "select * from student_info where name like " }

List readXls() InputStream is = HSSFWorkbook hssfWorkbook = Student student = List list = ArrayList ( numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++ HSSFSheet hssfSheet = (hssfSheet == ( rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++ HSSFRow hssfRow = (hssfRow != student = HSSFCell no = hssfRow.getCell(0 HSSFCell name = hssfRow.getCell(1 HSSFCell age = hssfRow.getCell(2 HSSFCell score = hssfRow.getCell(3 @SuppressWarnings("static-access" (hssfCell.getCellType() == } (hssfCell.getCellType() == } }

@SuppressWarnings({ "rawtypes" save() ReadExcel xlsMain = Student student = List list = ( i = 0; i < list.size(); i++ student = List l = DbUtil.selectOne(Common.SELECT_STUDENT_SQL + "'%" + student.getName() + "%'" (!l.contains(1 } System.out.println("The Record was Exist : No. = " + student.getNo() + ",Name = " + student.getName() + ",Age = " + student.getAge() + ",and has been throw away!" }

insert(String sql,Student student) Connection conn = PreparedStatement ps = conn = ps = ps.setString(1 ps.setString(2 ps.setString(3 ps.setString(4 flag = (! System.out.println("Save data : No. = " + student.getNo() + ",Age = " + student.getAge() + " succeed!" } } (ps != (conn != @SuppressWarnings({ "unchecked","rawtypes" List selectOne(String sql,Student student) Connection conn = PreparedStatement ps = ResultSet rs = List list = conn = ps = rs = (rs.getString("no").equals(student.getNo()) || rs.getString("name").equals(student.getName())|| rs.getString("age" list.add(1 } list.add(0 } } (rs != (ps != (conn != ResultSet selectAll(String sql) Connection conn = PreparedStatement ps = ResultSet rs = conn = ps = rs = } } (rs != (ps != (conn != }

.id = .no = .name = .age = setScore( .score = }

源码下载:

========================================================

多读一些书,英语很重要。

More reading,and english is important.

I'm Hongten

hongten

========================================================?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读