2015-04-20 193 views
-1

我使用了一個代碼,可以讓我以圖形方式查看處理結果。我想將圖存儲在MySql數據庫中(在WampServer中)。我怎樣才能做到這一點?在數據庫中存儲圖像

這是我曾嘗試:

if (jCheckBox1.isSelected()) { 
    try { 
     con = getConnection("jdbc:mysql://localhost:3306/base_rapport_tt", "root", ""); 
     Statement statement = con.createStatement(rs.TYPE_FORWARD_ONLY, rs.CONCUR_READ_ONLY); 
     String sql1 = "Select last_updated_by,(count(id_incident))*100/(Select count(id_incident) from incident where Status like 'Closed' and open_time between '" + jTextField1.getText() + "' and '" + jTextField2.getText() + "')from incident where Status like 'Closed'and open_time between '" + jTextField1.getText() + "' and '" + jTextField2.getText() + "' group by last_updated_by"; 
     rs1 = statement.executeQuery(sql1); 
     DefaultPieDataset pieDataset = new DefaultPieDataset(); 
     while (rs1.next()) { 
      pieDataset.setValue(rs1.getString("last_updated_by"), rs1.getDouble(2)); 
     } 
     JFreeChart chart = ChartFactory.createPieChart3D("Taux résolution par personne", pieDataset, true, true, false); 
     PiePlot3D piePlot3d = (PiePlot3D) chart.getPlot(); 
     piePlot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}")); 
     fenetre fen1 = new fenetre(); 
     pnl = new JPanel(new BorderLayout()); 
     fen1.setContentPane(pnl); 
     fen1.setVisible(true); 
     setSize(700, 700); 
     ChartPanel cPanel1 = new ChartPanel(chart); 
     pnl.add(cPanel1); 
    } catch (Exception e) { 
     JOptionPane.showMessageDialog(this, e); 
    } 
} 
+0

您也可以在base64中轉換圖像並將其保存爲字符串 –

+0

我該怎麼做? – nabil123456

+0

http://stackoverflow.com/questions/6150289/how-to-convert-image-into-base64-string-using-javascript –

回答

2

一般情況下,是的,你可以在MySQL中使用BLOB類型存儲任意的二進制數據。一個例子模式:

CREATE TABLE images (
    id INT PRIMARY KEY AUTO_INCREMENT, 
    description VARCHAR(40), 
    data BLOB 
); 

看來你使用的後端Java中,如果這樣你應該看看Using Large Objects教程。

但是,有些原因可能你不想這樣做;有關這方面的一些討論見Should I use MySQL blob field type?