Guest User

Untitled

a guest
May 10th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. <%@ page import="java.io.*,java.sql.*,eskuel.CMI_SQL" %>
  2.  
  3. <html>
  4. <%
  5. String contentType = request.getContentType();
  6. if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
  7. DataInputStream in = new DataInputStream(request.getInputStream());
  8. int formDataLength = request.getContentLength();
  9. byte dataBytes[] = new byte[formDataLength];
  10. int byteRead = 0;
  11. int totalBytesRead = 0;
  12.  
  13. while (totalBytesRead < formDataLength) {
  14. byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
  15. totalBytesRead += byteRead;
  16. }
  17. String file = new String(dataBytes);
  18. String saveFile = file.substring(file.indexOf("filename=\"") + 10);
  19. System.out.println("saveFile=" + saveFile);
  20. saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
  21. System.out.println("saveFile" + saveFile);
  22. saveFile = file.substring(file.indexOf("filename=\"") + 10);
  23. saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
  24. saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
  25. int lastIndex = contentType.lastIndexOf("=");
  26. String boundary = contentType.substring(lastIndex + 1, contentType.length());
  27. int pos;
  28.  
  29. pos = file.indexOf("filename=\"");
  30. pos = file.indexOf("\n", pos) + 1;
  31. pos = file.indexOf("\n", pos) + 1;
  32. pos = file.indexOf("\n", pos) + 1;
  33. int boundaryLocation = file.indexOf(boundary, pos) - 4;
  34. int startPos = ((file.substring(0, pos)).getBytes()).length;
  35. int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
  36.  
  37. FileOutputStream fileOut = new FileOutputStream(saveFile);
  38. fileOut.write(dataBytes, startPos, (endPos - startPos));
  39.  
  40. %>
  41. <b>File <% out.println(saveFile);%> has been uploaded and inserted into Database.</b>
  42. <%
  43.  
  44.  
  45. String bestandsNaam = saveFile;
  46. String rij;
  47.  
  48. FileInputStream fis = new FileInputStream(bestandsNaam);
  49. DataInputStream myInput = new DataInputStream(fis);
  50.  
  51.  
  52. while ((rij = myInput.readLine()) != null) {
  53. String kolom[] = rij.split(",");
  54.  
  55. CMI_SQL sql = new CMI_SQL("jdbc:mysql://mysql.cmi-hro.nl:3306/bla", "bla", "bla");
  56.  
  57.  
  58. String query1 = "INSERT INTO KLANT VALUES(" + kolom[0] + "," + kolom[1] + ")";
  59. String query2 = "INSERT INTO KLANT_GEGEVENS VALUES(" + kolom[0] + "," + kolom[2] + "," + kolom[3] + "," + kolom[4] + "," + kolom[5] + ");";
  60. String query3 = "INSERT INTO REIS_GEGEVENS VALUES(" + kolom[0] + "," + kolom[6] + "," + kolom[7] + ");";
  61. sql.updateQuery(query1);
  62. sql.updateQuery(query2);
  63. sql.updateQuery(query3);
  64.  
  65.  
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75. %>
  76. </html>
Add Comment
Please, Sign In to add comment