如何在ireport中使用javabean数据源

wuliaowuliaoren 2004-09-02 04:10:18
如何在ireport中使用javabean数据源
...全文
126 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qjhaaaaa 2004-09-03
public static Connection connectPostgers() throws SQLException
{
Connection mycon = null;

if (databaseDrvName == "")
{
databaseDrvName = "org.postgresql.Driver";
}
if (databaseURL=="")
{
databaseURL = "jdbc:postgresql://172.25.4.27/PTSII";
}
if (databaseUSER=="")
{
databaseUSER = "postgres";
}
if (databasePWD=="")
{
databasePWD = "";
}

try
{
Class.forName(databaseDrvName);
mycon = DriverManager.getConnection(databaseURL, databaseUSER,databasePWD);
}
catch (SQLException sqle)
{
System.out.println("connectDB() error:" + sqle.getMessage());
sqle.printStackTrace();
throw sqle;
}
catch (ClassNotFoundException cnfe)
{
System.out.println("connectDB() ClassNotFound error:" + cnfe.getMessage());
cnfe.printStackTrace();
throw new SQLException("ConnectDB() ClassNotFound error:" + cnfe.getMessage());
}

return mycon;
}

<%
File reportFile = new File(application.getRealPath("/reports/testparamter.jasper"));

Map parameters = new HashMap();
String sql = "SELECT * FROM balance_table WHERE part>='CACM104016-00B' AND part<='CAET000009-00A'";
//parameters.put("ReportTitle", "Address Report");
//parameters.put("BaseDir", reportFile.getParentFile());
parameters.put("SQLSTR",sql);
Connection conn = connectionDB.connectPostgers();
if(conn!= null){
System.out.println("connection success !");
}else{
System.out.println("connection fail !");
}

byte[] bytes =JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,conn);
response.setContentType("application/pdf");

response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
%>

回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-02 04:10
社区公告
暂无公告