Error eka kothanada enne?
(DB connection da? data insert keranakotada? exception stacktrace eka thiyenawada?)
Create a File object, Create a FileInputStream, Use a PreparedStatement and the setBinaryStream method
or
keep the image in file system and store the relative path of it in DB as a text field
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
int retVal = chooser.showOpenDialog(this);
File myFile = chooser.getSelectedFile();
Image resizedImage = ImageIO.read(myFile).getScaledInstance(Picture.getWidth(),Picture.getHeight(),Image.SCALE_SMOOTH);
ImageIcon imageIcon = new ImageIcon(resizedImage);
Picture.setIcon(imageIcon);//Load image into a jlabel(Picture)
}catch( IOException e ){
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Icon ico = Picture.getIcon();
// Create a buffered image
BufferedImage bimg = new BufferedImage(ico.getIconWidth(), ico.getIconHeight(),BufferedImage.TYPE_INT_RGB);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(bimg, "png", baos);
} catch (IOException ex) {
Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
}
InputStream is = new ByteArrayInputStream(baos.toByteArray());
PreparedStatement pst;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String DB = "D:\\Info";
String URL="jdbc

dbc

RIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+DB+".accdb;";
Connection con = DriverManager.getConnection(URL);
String Insrt = "insert into Info(ID,Picture) values (?,?)";
pst = con.prepareStatement(Insrt);
pst.setBinaryStream(1,is,(int)baos.toByteArray().length);
pst.executeUpdate();
}catch(ClassNotFoundException | SQLException e){
System.out.print(e);
}
}
error
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect