1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public void storeChart(JFreeChart chart, String x, String y, String comments) throws SQLException, IOException {
modifySequenceTable("resultimage");
//Recovery the last id simulation
String query_select = "SELECT id FROM simulation";
ResultSet res = state.executeQuery(query_select);
res.last();
int id_fk = res.getInt("id");
String query_nb_run = "SELECT count(*) FROM resultimage WHERE simulation_id="+id_fk;
ResultSet res_nb_run = state.executeQuery(query_nb_run);
res_nb_run.last();
int nb_run = res_nb_run.getInt("count");
Object[] p = ExtractParamSimulationGroup();
String name = p[0]+"_run"+nb_run;
File image = new File("..\\Chart.png");
FileInputStream imagestream = new FileInputStream(image);
String query_insert = "INSERT INTO resultimage (name, x, y, comments, simulation_id, image) ";
query_insert += "VALUES (?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(query_insert);
ps.setString(1, name);
ps.setBinaryStream(6, imagestream, (int)image.length());
ps.setString(2, x);
ps.setString(3, y);
ps.setString(4, comments);
ps.setInt(5, id_fk);
ps.executeUpdate();
ps.close();
} |
Partager