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
   |  
 
 Connection connection = null;
String driverName1 = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName1);
String serverName = "10.133.40.425";
String portNumber = "1521";
String sid = "final";
String url1 = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid;
   String username1 = "sasa";
String password1 = "saze";
connection = DriverManager.getConnection(url1, username1, password1);
 
	 FileOutputStream fileOut;
					POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:\\approchement\\table.xls"));
					HSSFWorkbook wb = new HSSFWorkbook(fs);
					HSSFSheet sheet = wb.getSheetAt(5);
 
					List sheetData = new ArrayList();
					 Iterator rows = sheet.rowIterator();
 
					while (rows.hasNext()) {
				    	   Row row = (Row) rows.next();
				    	   Iterator cells = row.cellIterator();
				           List data = new ArrayList();
				           while (cells.hasNext()) {
				        	   Cell cell = (Cell) cells.next();
				               data.add(cell);
			    	       }
			    	       sheetData.add(data);
 
 
				       }
 PreparedStatement stmt = connection.prepareStatement("INSERT INTO table1(nom,prénom) VALUES(?,?)");
 for (int i = 0; i < sheetData.size(); i++) {
	  List list = (List) sheetData.get(i);
 
	    	  for (int j = 0; j < list.size(); j++) {
 
	    		  Cell cell = (Cell) list.get(j);
 
	    		  switch (cell.getColumnIndex()) {
	    		  case 0: 
	   stmt.setString(1, cell.getStringCellValue());
 
	    		  case 1: 
	  stmt.setString(2, cell.getStringCellValue());
 
	    		  }
	      }
	    }
 stmt.executeUpdate(); | 
Partager