Java 使用jaybird 2.1.6在blob字段中插入文件
我正在尝试使用lib-jaybird 2.1.6在Firebird数据库的blob字段中插入一个文件 首先,我在数据库中创建一条记录,然后,使用记录id,尝试将文件插入blob(子类型0)字段中 这是我的密码:Java 使用jaybird 2.1.6在blob字段中插入文件,java,file,blob,firebird,jaybird,Java,File,Blob,Firebird,Jaybird,我正在尝试使用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_ME
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中?setBinaryStream(int,InputStream,long)是一种JDBC4(Java 6)方法
据我所知,Jaybird仍然是JDBC3,因此您需要使用PreparedStatement.setBinaryStream(int,InputStream,int)
:
ps.setBinaryStream(paramIdx++, input, (int)p_file.length());