首先,我希望能够使用手机拍摄图像,使用位图之类的内容,然后将照片上传到MySQL。后来我想要撤回该图像,也就是放在应用程序的其他地方。
这就是我所拥有的(它不起作用,因为我需要将图像放在文件位置而不是位图。):
public static void InsertImage(String user_id, String gender, Blob image, String filePath) {
connection(); //this is where i got my connection information this works fine btw.
filePath = "i don't want to have anything here";
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("INSERT INTO picture (user_id, gender, image) VALUES(?, ?, ?)");
statement.setString(2, user_id);
statement.setString(3, gender);
InputStream inputStream = new FileInputStream(new File(filePath));
statement.setBlob(8, image);
statement.executeUpdate();
statement.close();
connect.close();
//3 means column
System.out.println("Worked");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
另外我该如何撤回呢?此外,如果使用位图不起作用,因为它是我在mySQL中使用的Blob,我还能使用什么?链接到任何教程将是伟大的,最好是视频..我讨厌阅读:s