-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path新建文本文档.txt
65 lines (60 loc) · 2.04 KB
/
新建文本文档.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.wise.excel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExportExcel {
public static void main(String[] args) throws SQLException, ClassNotFoundException, FileNotFoundException, IOException {
// TODO Auto-generated method stub
XSSFWorkbook workbook = new XSSFWorkbook( new FileInputStream("E:\\111.xlsx"));
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.6.32:1521:wisebom", "wisebom", "wisebom");
PreparedStatement stamt = conn.prepareStatement("insert into HOU_TEST values (sys_guid(),?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?) ");
//stamt.addBatch(sql);
Iterator<XSSFSheet> sheetIter = workbook.iterator();
while(sheetIter.hasNext()){
XSSFSheet sheet = sheetIter.next();
Iterator<Row> rowIter = sheet.iterator();
while(rowIter.hasNext()){
Row row = rowIter.next();
Iterator<Cell> cellIter = row.iterator();
int indexNum = 1;
while(cellIter.hasNext()){
Cell cell = cellIter.next();
int cellType = cell.getCellType();
String value = "";
switch (cellType){
case Cell.CELL_TYPE_STRING:
value = cell.getStringCellValue();break;
case Cell.CELL_TYPE_NUMERIC:
value = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_BLANK:
value = "";
break;
default:break;
}
stamt.setString(indexNum++, value);
}
stamt.addBatch();
}
}
stamt.executeBatch();
conn.commit();
conn.close();
}
}