将图像存储在数据库中

时间:2015-04-20 13:43:50

标签: java mysql

我使用的代码可以让我以图形方式查看治疗结果。我想将图形存储在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);
    }
}

1 个答案:

答案 0 :(得分:2)

通常,是的,您可以使用BLOB类型在MySQL中存储任意二进制数据。示例模式:

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?