Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addAndUpdateFileToListRoom() throws IOException, SQLException, ClassNotFoundException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://172.16.1.38:3306/athomcorp","scordova","sebastian");
- con.setAutoCommit(false);
- PreparedStatement pstm = null ;
- FileInputStream input = new FileInputStream("C:\Users\Sebastian\Documents\export_room.xlsx");
- XSSFWorkbook wb = new XSSFWorkbook(input);
- XSSFSheet sheet = wb.getSheetAt(0);
- Row row;
- for(int i=1; i<=sheet.getLastRowNum(); i++){
- row = sheet.getRow(i);
- String name = row.getCell(0).getStringCellValue().toString();
- String direccion = row.getCell(1).getStringCellValue().toString();
- double longitud = row.getCell(2).getNumericCellValue();
- double latitud = row.getCell(3).getNumericCellValue();
- String sql = "INSERT INTO geojson (name, direccion, longitud, latitud)"
- + " VALUES('"+name+"','"+direccion+"','"+longitud+"','"+latitud+"')";
- pstm = (PreparedStatement) con.prepareStatement(sql);
- pstm.executeUpdate();
- System.out.println("Import rows "+i);
- }
- con.commit();
- pstm.close();
- con.close();
- input.close();
- System.out.println("Success import excel to mysql table");
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment