Guest User

Untitled

a guest
Apr 10th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public void addAndUpdateFileToListRoom() throws IOException, SQLException, ClassNotFoundException {
  2.  
  3. try {
  4.  
  5. Class.forName("com.mysql.jdbc.Driver");
  6. Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://172.16.1.38:3306/athomcorp","scordova","sebastian");
  7. con.setAutoCommit(false);
  8. PreparedStatement pstm = null ;
  9. FileInputStream input = new FileInputStream("C:\Users\Sebastian\Documents\export_room.xlsx");
  10.  
  11. XSSFWorkbook wb = new XSSFWorkbook(input);
  12. XSSFSheet sheet = wb.getSheetAt(0);
  13. Row row;
  14. for(int i=1; i<=sheet.getLastRowNum(); i++){
  15. row = sheet.getRow(i);
  16.  
  17. String name = row.getCell(0).getStringCellValue().toString();
  18. String direccion = row.getCell(1).getStringCellValue().toString();
  19. double longitud = row.getCell(2).getNumericCellValue();
  20. double latitud = row.getCell(3).getNumericCellValue();
  21. String sql = "INSERT INTO geojson (name, direccion, longitud, latitud)"
  22. + " VALUES('"+name+"','"+direccion+"','"+longitud+"','"+latitud+"')";
  23. pstm = (PreparedStatement) con.prepareStatement(sql);
  24. pstm.executeUpdate();
  25. System.out.println("Import rows "+i);
  26. }
  27. con.commit();
  28. pstm.close();
  29. con.close();
  30. input.close();
  31. System.out.println("Success import excel to mysql table");
  32. }
  33. catch (IOException e) {
  34. e.printStackTrace();
  35. }
  36. }
Add Comment
Please, Sign In to add comment