我正在尝试使用lib jaybird 2.1.6在Firebird数据库的blob字段中插入一个文件。
首先,我在数据库中创建一条记录,然后使用记录的id,尝试将文件插入到blob (子类型0)字段中。
下面是我的代码:
public static boolean insertBlob(File p_file, String p_maxId) {
String requette =
"UPDATE MAIL_RECU a SET a.CONTENU=? where a.ID_MESSAGE_RECU="+ p_maxId;
PreparedStatement ps = null;
FileInputStream input = null;
try {
ps = laConnexion.prepareStatement(requette);
input = new FileInputStream(p_file);
int paramIdx = 1;
ps.setBinaryStream(paramIdx++, input, p_file.length());
ps.executeUpdate();
} catch (SQLException e) {
System.out.println("cause: " + e.getCause());
System.out.println("stacktrace: " + e.getStackTrace());
System.out.println(e);
messageUtilisateur.affMessageException(e,
"Erreur à l'insertion d'un blob");
} catch (FileNotFoundException e) {
messageUtilisateur.affMessageException(e,
"impossible de trouver le fichier");
} finally {
try {
ps.close();
input.close();
} catch (SQLException e) {
messageUtilisateur.affMessageException(e,
"Erreur à l'insertion d'un blob");
} catch (IOException e) {
messageUtilisateur.affMessageException(e, "fichier non trouvé");
}
}
return true;
}问题是我有一个例外,当
ps.setBinaryStream(paramIdx++, input, p_file.length());将被执行。
我收到一条消息"java.sql.SQLException:尚未实现“。我的问题是,有人已经有这个问题了吗?如果是,他(或她)是如何修复它的?有没有其他方法可以用jaybird在blob中存储文件?
发布于 2011-06-22 17:22:58
setBinaryStream(int, InputStream, long)是一种JDBC4 (Java6)方法。
据我所知,Jaybird仍然是JDBC3,所以你需要改用PreparedStatement.setBinaryStream(int, InputStream, int):
ps.setBinaryStream(paramIdx++, input, (int)p_file.length());https://stackoverflow.com/questions/6437473
复制相似问题