我正在尝试使用Netbeans将图像添加到数据库中,但对我来说不起作用
这是我的代码
当我转到mysql时,我看到的图像只有八位位组大小(BLOB-50 o)

    String code=jTextField1.getText();
    String reference=jTextField2.getText();
    String nom=jTextField3.getText();
    String marque=jTextField4.getText();
    String dimention=jTextField5.getText();
    String quantite=jTextField6.getText();
    String discription=jTextPane1.getText();
    String famille =jTextField7.getText();
    String code_famille =jTextField10.getText();
    String sousfamille=jTextField8.getText();

    String requete="insert into piece (Code_Piece,Reference,Nom_P,Mark_P,Dimention,Quantite,Categorie,Type,Discription,Image) VALUES('"+
    code+"','"+reference+"','"+nom+"','"+marque+"','"+dimention+"','"+quantite+"','"+Cate+"','"+Type+"','"+discription+"','"+imgPath+"')";

最佳答案

我的班级里也有这段代码

JFileChooser file = new JFileChooser();
file.setCurrentDirectory(new File(System.getProperty("user.home")));
FileNameExtensionFilter filter = new
FileNameExtensionFilter("*.images","jpeg","jpg","png","bmp");
 file. addChoosableFileFilter(filter);
int result = file.showSaveDialog(null);
 if (result == JFileChooser.APPROVE_OPTION)
 {
 File selectedFile = file.getSelectedFile();
 String path = selectedFile.getAbsolutePath();
 lbl_image.setIcon(ResizeImage(path, null));
 imgPath = path;
 }

else if (result == JFileChooser.CANCEL_OPTION){
 System.out.println("No Fille Selected");
 }

07-24 15:38