하늘을향해
Home
Tag
MediaLog
LocationLog
Guestbook
Admin
Write
Search
calendar
«
2025.5
»
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
total
today
yesterday
티스토리 가입하기
Category
분류 전체보기
(218)
프론트 플랫폼
(3)
Vue.js
(3)
JAVA언어
(40)
applet
(5)
JavaScript
(31)
Ajax
(2)
HTML
(17)
ActionScript
(2)
플랙스,플래쉬
(3)
PHP
(3)
안드로이드
(4)
AWS
(1)
was관련
(12)
Jboss
(2)
tomcat
(6)
JAVA오픈소스
(16)
Spring
(13)
mybatis
(2)
Spring Boot
(0)
linux(ubuntu)
(5)
영어문법
(3)
개인적인지식&취미
(4)
참조싸이트
(21)
maven
(6)
docker
(4)
Database관련
(28)
MYSQL
(10)
Oracle
(17)
카산드라
(1)
엘라스틱서치
(1)
office
(1)
기타
(2)
쏘스올릴떄씀
(0)
jasper report 5.5 jxml과 DB를 이용한 리포트 띄우기!
2013. 11. 1. 11:35
카테고리 없음
JAVASOURCE (report3.jrxml은 ireport를 이용해서 생성 해야함.)
package test; import java.sql.Connection; import java.sql.DriverManager; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; public class Test { /** The connection. */ static Connection connection = null; /** * Connect database. */ static void ConnectDatabase() { try { // Load the JDBC driver String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; Class.forName(driverName); // Create a connection to the database String url = "jdbc:sqlserver://127.0.0.1\\testdb:2433;databaseName=testdb;"; String username = "tester"; String password = "test!"; connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { System.err.println("Could not find the database driver"); } catch (Exception e) { System.err.println("Could not connect to the database"); } } /** * The main method. * * @param args the arguments */ public static void main(String[] args) { JasperReport jasperReport; JasperPrint jasperPrint; long start = System.currentTimeMillis(); try { // Log log4j configuration System.out.println("Start"); System.out.println("--------"); System.out.println("Compile Jasper XML Report"); jasperReport = JasperCompileManager.compileReport("src/test/report3.jrxml"); System.out.println("time : " + (System.currentTimeMillis() - start)+ " ms."); System.out.println("Create Database connection"); ConnectDatabase(); System.out.println("time : " + (System.currentTimeMillis() - start)+ " ms."); System.out.println("Create parameters"); Map <String, Object> parameters = new HashMap<String, Object>(); parameters.put("ReportTitle", "User Report"); parameters.put("DataFile", "src/test/report3.jasper"); parameters.put("IdRange", 10); System.out.println("Generated report"); jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection); System.out.println("time : " + (System.currentTimeMillis() - start)+ " ms."); System.out.println("Generated PDF"); JasperExportManager.exportReportToPdfFile(jasperPrint, "c:\\a\\test.pdf"); System.out.println("time : " + (System.currentTimeMillis() - start)+ " ms."); } catch (Exception e) { e.printStackTrace(); } System.out.println("--------"); System.out.println("Done"); } }
공유하기
게시글 관리
하늘을향해
posted by
천상의날개
티스토리툴바