PSQLException:错误:无法打开服务器文件“path/photo.jpg”:没有这样的文件或目录
问题描述:
如何在Postgresql中插入碘照片? 我有这些照片在服务器上,我不能在Postgresql数据库中插入lo_import。PSQLException:错误:无法打开服务器文件“path/photo.jpg”:没有这样的文件或目录
private static void insertPhoto(String nom,int pos) throws SQLException {
Statement stmt = connection.createStatement();
String path = "http://10.0.0.84/stade_photo/"+pos+".jpg";
System.out.println(path);
String sql = "UPDATE stadephenologique SET photo= "
+ "lo_import('"+path+"') WHERE nom='"+nom.replaceAll("'", "''")+"'";
stmt.executeUpdate(sql);
stmt.close();
connection.commit();
System.out.println(nom);
}
这是个例外:
Opened database successfully http://10.0.0.84/stade_photo/1.jpg Exception in thread "main" org.postgresql.util.PSQLException: ERROR: could not open server file " http://10.0.0.84/stade_photo/1.jpg ": No such file or directory
答
我已经改变照片BYTEA的类型和它的工作对我来说这个功能
private static void insertPhoto(String nom,int pos) throws SQLException, FileNotFoundException {
String path = "stade_photo/"+pos+".jpg";
System.out.println(path+" nom="+nom);
PreparedStatement pstmt = connection.prepareStatement("UPDATE stadephenologique SET photo = ? WHERE nom = ?");
File file = new File(path);
FileInputStream in = new FileInputStream(file);
try
{
pstmt.setBinaryStream(1, in, (int) file.length());
pstmt.setString(2, nom);
pstmt.executeUpdate();
connection.commit();
}
catch (Exception ee)
{
System.out.println("Exception is:- " + ee);
}
}
'lo_import'只能访问文件存储在运行Postgres的服务器上。它无法读取远程计算机上的文件,也无法通过http协议读取文件 –