相关疑难解决方法(0)

关于bytearrays的postgres jdbc 8.4和9之间有什么变化?

我正在使用PostgreSQL 9.0运行Mac OSX 10.6.我写了一个简单的Java应用程序,它在一个bytea字段中插入一个图像,然后查询相同的字段来检查它.

桌子:

 CREATE TABLE test.test_table
   (
   id integer NOT NULL,
  image bytea,
  CONSTRAINT test_table_pkey PRIMARY KEY (id)
);
Run Code Online (Sandbox Code Playgroud)

该计划类似于:

//insert the file
    PreparedStatement ps = connection.prepareStatement("INSERT INTO test.test_table( id, image ) VALUES (?, ?);");
            byte[] bytesFromFile = readFile("img/test1.bmp");
            ps.setInt(1, 1);
            ps.setBytes(2, bytesFromFile);
            ps.execute();
            ps.close();

            PreparedStatement stmt = connection.prepareStatement("Select id,image from test.test_table");
            ResultSet rs = stmt.executeQuery();
    //Get the file from the BD  and save it to the FS 
            while (rs.next()) {
                String id = rs.getString(1);
                InputStream imageStream = …
Run Code Online (Sandbox Code Playgroud)

java postgresql jdbc

7
推荐指数
1
解决办法
4720
查看次数

如何从数据库插入图像?

我希望在Jaspersoft Studio的报告中插入来自数据库的数据.
该JPG图像都在现场保存在MySQL imgdata类型LONGBLOB.
我试图把这个表达式放在Image元素中:

  1. $F{imgdata}
  2. MyUtil.getInputStream($F{imgdata})

在第一种情况下,我收到此错误:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRException: Unknown image source class [B
Run Code Online (Sandbox Code Playgroud)

......在第二种情况下,这个错误:

net.sf.jasperreports.engine.JRException:
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error
evaluating expression :  Source text :
MyUtil.getInputStream($F{imgdata})
Run Code Online (Sandbox Code Playgroud)

我的问题:如何将数据库中的图像插入到JasperReports的报告中?

mysql database image jasper-reports

3
推荐指数
2
解决办法
7656
查看次数

标签 统计

database ×1

image ×1

jasper-reports ×1

java ×1

jdbc ×1

mysql ×1

postgresql ×1