Tag: bytea

如何使用Java将bytea列作为文件下载

我想使用java下载以bytea格式存储的文件。 我没有超级用户权限。 使用下面的代码我下载hex编码文件并将其转换为pdf但转换后的pdf损坏,而如果我使用\ copy函数(不能在java中使用)通过终端复制,下载过程可以顺利进行。 String sql = “(SELECT encode(f,’hex’) FROM test_pdf where id=’2′ LIMIT 1)”; System.out.println(sql); CopyManager copyManager = new CopyManager((BaseConnection) conn); FileWriter filew = new FileWriter(“/home/sourabh/image.hex”); copyManager.copyOut(“COPY “+sql+” TO STDOUT “, filew );` 然后 : xxd -p -r image.hex > image.pdf

适用于Hibernate pojo中@lob的hibernate映射。 我们正在使用hibernate映射。 你能告诉我@lob注释的等价物吗?

我们正在使用hibernate映射。 在hibernate配置文件中,我们给出了type =“blob”和pojo类getBlob以及setBlob方法。 除此之外,我们需要让@lob正确。 什么是hibernate映射中的lob的等价物 @Override public Hospital getHospital(long hospId, String hospitalName) { Hospital hos= hibernateTemplate.find(“from Hospital hos where hos.id = ? and hos.name = ? “, hospId,hospitalName); } @Transactional public void saveHospital(Hosipital hos) { Blob blob = Hibernate.getLobCreator(hibernateTemplate.getSessionFactory().getCurrentSession()).createBlob(hos.getContent()); hos.setHospitalImage(blob); hibernateTemplate.saveOrUpdate(“Hospital”, hos); }

使用Java在Postgresql中存储和检索图像

我是Java编程的新手,我正在搜索Java代码以在PostgreSQL中存储图像并检索图像。 在PostgreSQL中,我使用了Bytea Data-type。 图像已存储。 但是当我检索时我得到了NULL。 我无法得到图像。 对此或任何其他建议的任何示例都会有所帮助。