Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. **the html code attach.html**
  2. <!DOCTYPE html>
  3. <!--
  4. To change this license header, choose License Headers in Project Properties.
  5. To change this template file, choose Tools | Templates
  6. and open the template in the editor.
  7. -->
  8. <html>
  9. <head>
  10. <script type="text/javascript">
  11. </script>
  12. <title>Attach</title>
  13. </head>
  14. <body>
  15. <br />
  16. <br />
  17. <br>
  18. <center>
  19. <form name="attach" action="./upload_attach.jsp" method="post"
  20. ENCTYPE="multipart/form-data">
  21. <p><b>Upload No:</b><input type="text" name=num size=30> </p>
  22. <p>
  23. <input type="file" name="attach"/>
  24. </p>
  25. <br />
  26. <br>
  27. <input type="submit" name="upl" value="UPLOAD">
  28. </form>
  29. </center>
  30. </body>
  31. </html>
  32.  
  33. <%--
  34. Document : upload_atach
  35. Created on : 30 janv. 2016, 20:01:08
  36. Author : Techno
  37. --%>
  38.  
  39. <%@page import="java.io.FileInputStream"%>
  40. <%--@page contentType="text/html" pageEncoding="UTF-8"--%>
  41. <!DOCTYPE html>
  42. <%@ page contentType="text/html;charset=windows-1252"%>
  43. <%@ page import ="java.sql.*" %>
  44. <%@ page import ="javax.sql.*" %>
  45. <%@ page import ="javax.naming.InitialContext" %>
  46. <%@ page import ="java.sql.PreparedStatement.*" %>
  47. <%@page import="java.io.File"%>
  48. <form name="upload1" method=get>
  49. <%
  50. try
  51. {
  52. int up1=Integer.parseInt(request.getParameter("num"));
  53. String up2=request.getParameter("attach");
  54. File f=new File("C:\Users\Techno\Pictures\mc.jpg");
  55. FileInputStream input= new FileInputStream(f);
  56. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  57. Connection
  58. //con=DriverManager.getConnection("jdbc:odbc:bal aji","admin","qsg");
  59. con=DriverManager.getConnection("jdbc:sqlserver://TECHNOPC\SQLEXPRESS:1433;databaseName=gestion_courrier;user=sayf;password=sayf;");
  60.  
  61. PreparedStatement pst=con.prepareStatement("insert into upload values(?,?)");
  62. pst.setInt(1,up1);
  63. //pst.setBinaryStream(2,fis,(int)f.length());
  64. pst.setBinaryStream(2,input);
  65. pst.executeUpdate();
  66. pst.close();
  67. con.close();
  68. %>
  69. <center><h3>File Uploaded Successfull</h3></center>
  70. <%
  71. }
  72. catch(Exception e)
  73. {
  74. // System.out.println(e.toString());
  75. e.getMessage();
  76.  
  77.  
  78. %>
  79. <center><h3>File Does not Uploaded</h3></center>
  80. <%
  81. }
  82. %>
  83. </form>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement