Jump to content
We've recently updated our Privacy Statement, available here ×

supun151515

Members
  • Posts

    2
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by supun151515

  1. Hello Friends, Good day!, I have created jasper report inside Eclipse Luna java project.. I have imported all the jar files in 'jasperreports-6.0.0lib' and 'jasperreports-6.0.0dist'. But when I export Executable Jar file, it will become more than 50MB file. Also report.jrxml file has not included on it. I have three questions; 1. What are the exact Jasper jar files to import in Eclipse?? 2. How can I include report.jrxml file inside my exported Jar file. It should be secure and user should not able to edit the report 3. How can I display Jasper View inside java swing window object (not a separate window)? 4. What is the proper way to deploy the project with user-non editable package (related to 2nd question)? Below is my code; form1.java package jasper1;import jasper1.DB.database;import java.awt.EventQueue;import java.sql.Connection;import javax.swing.JFrame;import javax.swing.JButton;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.JLabel;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.view.JasperViewer;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;public class form1 { private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { form1 window = new form1(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } Connection conn = null; private JTextField text_Host; private JTextField text_DB; private JTextField text_User; private JTextField text_Pwd; /** * Create the application. */ public form1() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JButton btnNewButton = new JButton("Connect"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { btnNewButton.setText("Please wait..."); } @Override public void mouseReleased(MouseEvent e) { btnNewButton.setText("Connect"); } }); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { database.host = text_Host.getText(); database.db = text_DB.getText(); database.user = text_User.getText(); database.pwd = text_Pwd.getText(); conn = DB.Connector(); if(conn != null){ //JOptionPane.showMessageDialog(null, "Successfully Connected"); String reportPath = "reports/report.jrxml"; try { JasperReport jr = JasperCompileManager.compileReport(reportPath); //JOptionPane.showMessageDialog(null, conn); JasperPrint jp = JasperFillManager.fillReport(jr, null, conn); JasperViewer.viewReport(jp); conn.close(); } catch (Exception e1) { JOptionPane.showMessageDialog(null, e1.getMessage()); } return; } } }); btnNewButton.setBounds(73, 167, 130, 23); frame.getContentPane().add(btnNewButton); text_Host = new JTextField(); text_Host.setText("localhost"); text_Host.setBounds(93, 32, 110, 20); frame.getContentPane().add(text_Host); text_Host.setColumns(10); text_DB = new JTextField(); text_DB.setText("qatarclean"); text_DB.setBounds(93, 63, 110, 20); frame.getContentPane().add(text_DB); text_DB.setColumns(10); text_User = new JTextField(); text_User.setText("root"); text_User.setBounds(93, 94, 110, 20); frame.getContentPane().add(text_User); text_User.setColumns(10); text_Pwd = new JTextField(); text_Pwd.setText("supun123"); text_Pwd.setBounds(93, 125, 110, 20); frame.getContentPane().add(text_Pwd); text_Pwd.setColumns(10); JLabel lblHost = new JLabel("Host"); lblHost.setBounds(38, 31, 46, 23); frame.getContentPane().add(lblHost); JLabel lblDatabase = new JLabel("Database"); lblDatabase.setBounds(38, 63, 56, 20); frame.getContentPane().add(lblDatabase); JLabel lblUserName = new JLabel("User Name"); lblUserName.setBounds(38, 94, 67, 23); frame.getContentPane().add(lblUserName); JLabel lblPassword = new JLabel("Password"); lblPassword.setBounds(38, 125, 56, 20); frame.getContentPane().add(lblPassword); }}[/code]DB.java package jasper1;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.JOptionPane;public class DB { Connection conn = null; public static class database { public static String host; public static String db; public static String user; public static String pwd; } public static Connection Connector(){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://"+database.host+":3306/" +database.db ,database.user,database.pwd); return conn; } catch (Exception e){ JOptionPane.showMessageDialog(null, "Login Failed.n" + e); return null; } }}[/code] Thank You, Supun
×
×
  • Create New...