我正在使用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) 我希望在Jaspersoft Studio的报告中插入来自数据库的数据.
该JPG图像都在现场保存在MySQL imgdata类型LONGBLOB.
我试图把这个表达式放在Image元素中:
$F{imgdata}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的报告中?