Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. String fnm;
  2. String lnm;
  3. InputStream b;
  4. public String getFnm() {
  5. return fnm;
  6. }
  7. public void setFnm(String fnm) {
  8. this.fnm = fnm;
  9. }
  10. public String getLnm() {
  11. return lnm;
  12. }
  13. public void setLnm(String lnm) {
  14. this.lnm = lnm;
  15. }
  16. public InputStream getB() {
  17. return b;
  18. }
  19. public void setB(InputStream b) {
  20. this.b = b;
  21. }
  22.  
  23. public boolean insert(Pojo bean)
  24. {
  25. boolean check_connection=false;
  26.  
  27. try
  28. {
  29. System.out.println("inside Registration");
  30. Connection conn= (Connection) DBConnection.connect();
  31.  
  32. String sql = "INSERT INTO image1 (first_name, last_name, photo) values (?, ?, ?)";
  33. PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
  34. ps.setString(1,bean.getFnm());
  35. ps.setString(2,bean.getLnm());
  36. ps.setBlob(3, bean.getB());
  37. ps.executeUpdate();
  38. check_connection =true;
  39. conn.close();
  40. }
  41. catch(Exception e)
  42. {
  43. System.out.println(""+e);
  44. }
  45. return check_connection;
  46. }
  47.  
  48. // obtains input stream of the upload file
  49. inputStream = filePart.getInputStream();
  50. }
  51. Pojo p=new Pojo();
  52. p.setFnm(firstName);
  53. p.setLnm(lastName);
  54. if (inputStream != null) {
  55. // fetches input stream of the upload file for the blob column
  56. p.setB(inputStream);
  57. // statement.setBlob(3, inputStream);
  58. }
  59. BusinessLogic bl=new BusinessLogic();
  60. boolean b=bl.insert(p);
  61. if(b)
  62. {
  63. System.out.println("success");
  64. }
  65. else {
  66. System.out.println("success");
  67. }
  68.  
  69. public static Connection con;
  70. public static Connection connect()
  71. {
  72. try
  73. {
  74. Class.forName("com.mysql.jdbc.Driver");
  75. con=DriverManager.getConnection("jdbc:mysql://localhost:3306/img","root","");
  76. System.out.println("connected!!");
  77. }
  78. catch(Exception e)
  79. {
  80. System.out.println(e);
  81. }
  82. return con;
  83. }
  84. public static void close() throws SQLException
  85. {
  86. if(con!=null)
  87. {
  88. con.close();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement