如何在ireport中使用javabean数据源

wuliaowuliaoren 2004-09-02 04:10:18
如何在ireport中使用javabean数据源
...全文
183 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
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();
%>

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧