我尝试将图像(.jpg格式)和音频文件(.mp3格式)插入MySQL数据库。我失败了。
我已使用MEDIUMBLOB
作为两列的数据类型。任何人都可以提供帮助。
String INSERT_PICTURE = "INSERT INTO pictures(idpictures,photo) VALUES (?,?)";
File file = new File("c:/new/1.jpg");
fis = new FileInputStream(file);
pst = conn.prepareStatement(INSERT_PICTURE);
pst.setInt(1, 67);
pst.setBinaryStream(2, fis, (int) file.length());
pst.executeUpdate();
conn.commit();
答案 0 :(得分:0)
我已经使用MEDIUMBLOB作为两个列的数据类型
对于整数值,您应该将列设为整数。
你的桌子应该是:
CREATE TABLE image_table (
id int(5) NOT NULL,
image MEDIUMBLOB NOT NULL
);
如果这没有帮助,请提供有关问题的更多信息(例外,编译时..)或你得到的结果。