如何使用JAVA DATABASE CONNECTIVITY连接将音频文件插入MYSQL数据库
为了插入图像,我们使用
psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,photo) "
+ "values(?,?)");
psmnt.setLong(1, userId);
fis = new FileInputStream(photoFile);
psmnt.setBinaryStream(2, (InputStream) fis, (int) (photoFile
.length()));
/*
* executeUpdate() method execute specified sql query. Here this
* query insert data and image from specified address.
*/
int s = psmnt.executeUpdate();
要以3gp格式插入音频文件,使用JDBC
的代码是什么答案 0 :(得分:2)
代码应该完全相同:你需要确保你的音频文件足够小以适应列(如果我没记错的话,mediumblob是16MBits或者那些。数据库不关心它的音频或图像数据。
为了讨论:
psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,audiofile) "
+ "values(?,?)");
psmnt.setLong(1, userId);
fis = new FileInputStream(audioFile);
psmnt.setBinaryStream(2, (InputStream) fis, (int) (audioFile
.length()));
/*
* executeUpdate() method execute specified sql query. Here this
* query insert data and image from specified address.
*/
int s = psmnt.executeUpdate();
似乎公平?