Pozdrav, želim da prilikom klika na dugme program upiše u bazu:
*Ime
*Cenu
*Datum
*I Sliku
(Kao na slici dole)
E sada mi izlazi problem,
Ovo je kod sa dugmeta Insert. da li može neko da mi pomogne da rešim problem?
private void Btn_InsertActionPerformed(java.awt.event.ActionEvent evt) {
if(checkInputs()&& ImgPath != null)
{
try {
Connection con = getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO products(name,price,add_date,image)" + "values(?,?,?,?) ");
ps.setString(1, txt_name.getText());
ps.setString(2, txt_price.getText());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String addDate = dateFormat.format(txt_AddDate.getDate());
ps.setString(3, addDate);
InputStream img = new FileInputStream(new File(ImgPath));
ps.setBlob(4, img);
ps.executeUpdate();
/* Show_Products_In_JTable();*/
JOptionPane.showMessageDialog(null, "Data Inserted");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}else{
JOptionPane.showMessageDialog(null, "One Or More Field Are Empty");
}
System.out.println("Name => "+txt_name.getText());
System.out.println("Price => "+txt_price.getText());
System.out.println("Image => "+ImgPath);
}
|