Wednesday, August 18, 2010

How to connect to data source when making web report with Java reporting tool?

When I'm making web report, I need to connect to data source. But sometimes the data source is defined by myself,which makes it complex to connect to data sourc.


How to solve it easily?How to connect to data source when making web report with Java reporting tool?
Hi!


You can try RAQ Report. As a professional Java web-based reporting tool, RAQ Report givesout two methods to solve this problem.


1. Connect to data source with the API of RAQ Report. And the program is as follows:


context.setDefDataSourceName(';demo';);


context.setConnection(';demo';,con);


DataSourceConfig dsoc = new DataSourceConfig(2,


true, ';GBK';, ';GBK';, false);


context.setDataSourceConfig(';demo';, dsoc);





2.Link to data source with jdbc. And the program is as follows:


public java.sql.Connection getConnection() throws Exception {


Connection conn=null;


try{


Class.forName(';org.hsqldb.jdbcDriver';);


}catch(ClassNotFoundException cne){


cne.printStackTrace();


}


try{


conn= DriverManager.getConnection(';jdbc:hsqldb鈥?br>




}catch(SQLException e){


e.printStackTrace();


}


return conn;


}


When develop web reporting project, you can connect to data source easily with these two methods provided by RAQ Report. Accoding to real business, you can choose a better one.


For more details and graphic illustration, you can refer to my blog at http://freezea.blogspot.com/.


Good luck.How to connect to data source when making web report with Java reporting tool?
Which java reporting tool/engine you are taking about?


Is it jasper or something else ?

No comments:

Post a Comment