Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将任何图像作为Blob保存到MySQL_Java_Mysql_Blob - Fatal编程技术网

Java 将任何图像作为Blob保存到MySQL

Java 将任何图像作为Blob保存到MySQL,java,mysql,blob,Java,Mysql,Blob,我有这些代码在MySQL中保存图像,但它不起作用 FileInputStream fis = null; PreparedStatement ps = null; MyDB.con.setAutoCommit(false); File pic = new File(txtPicPath.getText().trim()); fis = new FileInputStream(pic); ps = MyDB.con.prepareStatement("insert into `photo`(`Em

我有这些代码在MySQL中保存图像,但它不起作用

FileInputStream fis = null;
PreparedStatement ps = null;
MyDB.con.setAutoCommit(false);
File pic = new File(txtPicPath.getText().trim());
fis = new FileInputStream(pic);
ps = MyDB.con.prepareStatement("insert into `photo`(`Employee ID`, Picture) values (?, ?)");
ps.setString(1, Data.User.getText());
ps.setBinaryStream(2, fis, pic.length());
ps.executeUpdate();
MyDB.con.commit();
JOptionPane.showMessageDialog(rootPane, "Upload Successfully");
btnPicdelete.setEnabled(true);
btnBrowse.setEnabled(false);
btnUpload.setEnabled(false);
txtPicPass.setText("");    
txtPicPath.setText("");
问题是:

java.io.FileNotFoundException: image1.jpg (The system cannot find the file specified)

我上传的图像名称是
image1.jpg

您需要在jTextField中指定图像的完整路径,或者您可以使用
getClass().getResource()
作为替代

例如:

URL url = this.getClass().getResource("../Image/pyPic.jpg");  
                InputStream is = url.openStream();  
我的文件名必须是:

txtPicPath.setText(file.getAbsoluteFile().toString())

错误明确表示
系统找不到指定的文件
。是否确实在指定的路径中有image1.jpg?请检查图像路径是否正确,或者是否已将文件放入正确的目录中。指定文件的完整路径。还要检查它是否存在。是的,这是因为我使用JFileChooser()获取@pradeepsimhat该图像位于桌面@AY89上,但现在如何将该图像固定到我的jlabel的宽度或大小@c、 普拉莫德