Skip to content

Instantly share code, notes, and snippets.

@sangpt
Created May 8, 2016 13:02
Show Gist options
  • Save sangpt/81ae6492fbff15388cc699caab4b73e8 to your computer and use it in GitHub Desktop.
Save sangpt/81ae6492fbff15388cc699caab4b73e8 to your computer and use it in GitHub Desktop.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package GUID;
import java.awt.Container;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.*;
/**
*
* @author Vaio
*/
public class Report extends JFrame {
public Report(String fileName) {
this(fileName, null);
}
public Report(String fileName, HashMap parameter) {
super("View Report");
try {
KetNoi kn = new KetNoi();
JasperPrint print = JasperFillManager.fillReport(fileName, parameter, Con());
JRViewer viewer = new JRViewer(print);
Container c = getContentPane();
c.add(viewer);
} catch (Exception ex) {
}
setBounds(10, 10, 600, 500);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
private Connection Con() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
try {
// conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/diemsv?characterEncoding=utf8", "root", "");
conn = DriverManager.getConnection("jdbc:mysql://sql6.freesqldatabase.com:3306/sql6118529?characterEncoding=utf8", "sql6118529", "Bf7vdQUsEA");
} catch (SQLException ex) {
Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, ex);
}
if (conn == null) {
System.out.println("Kết nối lỗi");
} else {
System.out.println("Kết nối thành công");
}
return conn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment