title: Insert image into MySQL
body: <p>I am doing create product using netbeans and mySQL. I used a file chooser to get the image from user when button is on click, for example:</p>
  
  <pre><code>public void handle(ActionEvent event){
       FileChooser fileChooser = new FileChooser();
  
          //Set extension filter
          FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
          FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
          fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);
  
          //Show open file dialog
          File file = fileChooser.showOpenDialog(null);
  
          try {
              BufferedImage bufferedImage = ImageIO.read(file);
              WritableImage image = SwingFXUtils.toFXImage(bufferedImage, null);
              myImageView.setImage(image);
          } catch (IOException ex) {
              Logger.getLogger(CreateProductUI.class.getName()).log(Level.SEVERE, null, ex);
          }
  }
  </code></pre>
  
  <p>And I display the image using code below:</p>
  
  <pre><code>Image image = panel.getMyImageView().getImage();
  </code></pre>
  
  <p>It works fine until I try to insert the image into database. This is my constructor and create method:</p>
  
  <pre><code>public Product(String name,String desc,double price, int quantity,String datestr,Image image){
      this.name = name;
      this.desc = desc;
      this.price = price;
      this.quantity = quantity;
      this.datestr = datestr;
      this.image = image;
  }
  
  public boolean create(){
      boolean success = false;
      DBController db = new DBController();
      String dbQuery; 
      db.getConnection();     
  
      dbQuery = "INSERT INTO sm_product(productName,productDescription,productPrice,productQuantity,dateOfCreation,productStatus,productImage) VALUES ('" + name + "', '" + desc + "', " + price + ", " + quantity + ",'" + datestr + "', 'Available', '" + image + "')";
  
      if (db.updateRequest(dbQuery) == 1){
          success = true;
      }
      db.terminate();
      return success;
  }
  </code></pre>
  
  <p>However, the image was stored as 'javafx.scene.image.WritableImage@3a6e48b3'. I tried twice with the same image but the address was different. I wonder am I storing image in a wrong way? I not sure whether I can retrieve the image using select SQL statement because I have not try yet but I think it does not work.</p>
  
  <p>Anybody has a better way to solve it because the image stored in database is very weird which I think it might be wrong.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Updated portion</strong></p>
  
  <pre><code>public void getConnection(){ 
      String url = ""; 
      try { 
          //url = "jdbc:mysql://172.20.133.227/test"; 
          url = "jdbc:mysql://localhost/amkcc"; 
          con = DriverManager.getConnection(url, "root", "root"); 
          System.out.println("Successfully connected to " + url+ "."); 
      } 
      catch (java.sql.SQLException e) { 
          System.out.println("Connection failed -&gt;"+ url); 
          System.out.println(e); 
      } 
  } 
  </code></pre>