title: How to go about saving an image in blob format to MySQL in Java
body: <p>For the purpose of a task I have to store an image into MySQL as a blob format (even though it would have been better and ideal to store the image path in the database and keep the image in a folder in localcopy).</p>
  
  <p>So far I have researched and couldn't find any answer that could help me, this is what I have done so far</p>
  
  <p>Soon as a button click, this will be fired:</p>
  
  <pre><code>empdao.insertImage(fis);
  </code></pre>
  
  <p>Image is populated on another even listener like this :</p>
  
  <pre><code>static FileInputStream fis = null;
  static String path = null;
  path = filechooser.getSelectedFile().getAbsolutePath();
  File image = new File(path);
  fis = new FileInputStream (image);
  </code></pre>
  
  <p>This code below takes care of adding it into the database.</p>
  
  <pre><code>public void insertImage(FileInputStream fis) throws SQLException {
  
  
  
  Connection c = getConnection();     
  
      String query = "INSERT INTO Picture (picture) VALUES (?)";
  
      System.out.println(query);
  
      PreparedStatement pstmt = c.prepareStatement(query);
  
      pstmt.setBinaryStream(1, fis);
  
      pstmt.executeUpdate();
  
      c.close();
  }
  </code></pre>
  
  <p>However the problem is that I needed it to convert it as a blob and I am not sure how to, can someone help me or guide me on how to go about storing the chosen image as a blob field into MySQL.</p>
  
  <p>Currently when it adds it into database I get java.io file input under the pictures column.</p>