Results 1 to 11 of 11
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Exclamation way to take printout from mysql

    Thanks For Your help on my previous forum's sir!

    i am going to complete my software sir,this is my 1st complete work,
    But! in the final step i wants to take paper printout from database,

    In DataBase is in the form of

    Java Code:
    EmployeeId	Saldate	Basic	Additionalpay	Spl	Other	Leavem	Gross	Netsal	Laveded	Loanamt	Festiveladv	
    108	2012-05-26	120000	0	0	0	0	120000	112000	-4000	0		8000	12000

    But i want to in the form of (Example only)

    way to take printout from mysql-pay.gif


    i need at least 3 pay slip per page when i pass the EmployeeId's


    I need your idea, i am new for this all. But i have confidence. If you guide me i can do this Perfectly..,

    Help Me Please Sir..,
    I am waiting for your response..,

    Thank You sir..,
    Last edited by raj.mscking@gmail.com; 06-05-2012 at 01:17 PM.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: way to take printout from mysql

    How would you implement the payslip? Is a plain text? I don't think so from the screen shot you've post. Is it a PDF document or is it in HTML or even an excel document. Please give us some more information.

  3. #3
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Exclamation Re: way to take printout from mysql

    Sorry For The Late Replay Sir!

    Thank you for your response sir..,

    Code for Action Listener is..,

    Java Code:
    private void jLabel113MouseClicked(java.awt.event.MouseEvent evt) {                                       
    // TODO add your handling code here:
         PrinterJob job = PrinterJob.getPrinterJob();
             job.setPrintable(this);
             boolean ok = job.printDialog();
             if (ok) {
                 try {
                      job.print();
                 } catch (PrinterException ex) {
                  /* The job did not successfully complete */
                 }
             }
             jLabel113.setVisible(false);
             jLabel114.setVisible(false);
    }

    Code For print method is..,

    Java Code:
    public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
     
            if (page > 0) { 
                return NO_SUCH_PAGE;
            }
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
     try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root");
            PreparedStatement ps100 = connn.prepareStatement("select EmployeeID from newemp where EmployeeID =?");
            ps100.setString(1, gtempid.getText());
            ResultSet rs100 = ps100.executeQuery();
            if (rs100.next()) {
                String id = rs100.getString(1);
                if(true) {
                   PreparedStatement ps1 = connn.prepareStatement("select s.EmployeeId,s.Saldate,"
                           + "s.Basic,s.Additionalpay,s.Spl,s.Other,s.Leavem,"
                           + "s.Gross,s.Netsal,s.Laveded,s.Loanamt,s.Festiveladv,"
                           + "s.Traveladv,s.Salaryadv,s.Othersded,s.Totded,s.Insurance,"
                           + "e.Designation,e.Name,e.Department,e.Branch from salarydet s,"
                           + "newemp e where s.EmployeeId=e.EmployeeID and s.EmployeeId=?");
                    ps1.setString(1, id);
                    ResultSet rs = ps1.executeQuery();
                    if (rs.next()) {
                        String lv=(rs.getString(7));
                int ll=(Integer.valueOf(lv)-1);
                String mm=(String.valueOf(ll));
                String nn;
                
                if(ll==-1)
                {
                    nn="Didn't Taken Any Leave";
                }
                else if(ll==-0)
                {
                    nn="Taken 1 Day";
                }
                else
                {
                    nn=(lv+" - 1 = "+ll);
                }
                        g.drawString("                             READ                ",200,20);  
                        g.drawString("===============================================================",100,30);
                                         
                       g.drawString("                            PAY SLIP                                   ",200,40);
                      
                       g.drawString("===============================================================",100,50);
                        
                        g.drawString("Employee Name  : "+rs.getString(19),100,60);g.drawString("Salary Date                 : "+df.format(rs.getDate(2)),350,60);
                        g.drawString("Employee ID        : "+rs.getString(1),100,70);g.drawString("Leave For This Month : "+nn,350,70);
                        g.drawString("Department          : "+rs.getString(20),100,80); g.drawString("Designation                 : "+rs.getString(18),350,80);
                        g.drawString("Branch                 : "+rs.getString(21),100,90);
                       // g.drawString();
                        g.drawString("===============================================================",100,100);
                        g.drawString("Gross Salary",100,110);     g.drawString("Amount",250,110); g.drawString("Deduction",330,110); g.drawString("Amount",480,110);
                        g.drawString("===============================================================",100,120);
                        //g.drawString();
                        g.drawString("Basic              ",100,130); g.drawString(rs.getString(3),250,130);g.drawString("Insurance",330,130);g.drawString(rs.getString(17),480,130);
                        g.drawString("Additional Pay",100,140);g.drawString(rs.getString(4),250,140);g.drawString("Leave Dedection",330,140);g.drawString(rs.getString(10),480,140);
                        g.drawString("Special",100,150);g.drawString(rs.getString(5),250,150);g.drawString("Loan Amount",330,150);g.drawString(rs.getString(11),480,150);   
                        g.drawString("Others",100,160);g.drawString(rs.getString(6),250,160);g.drawString("Festival Advance",330,160);g.drawString(rs.getString(12),480,160);
                        g.drawString("Traval Advance",330,170);g.drawString(rs.getString(13),480,170);
                        g.drawString("Salary Advance",330,180);g.drawString(rs.getString(14),480,180);
                        g.drawString("Gross Salary",100,200);g.drawString(rs.getString(8),250,200);g.drawString("Others",330,190);g.drawString(rs.getString(15),480,190);
                        g.drawString("Net Salary",100,210);g.drawString(rs.getString(9),250,210);g.drawString("Total Deduction",330,210);g.drawString(rs.getString(16),480,210);
                          }
                               }
            } else {
                JOptionPane.showMessageDialog(null, "Enter Valid ID Please");
            }
    connn.close();
        } catch (Exception e) {
            
            JOptionPane.showMessageDialog(null,e);
        }
            
            return PAGE_EXISTS;
        }

    Output Is (By Printer)

    way to take printout from mysql-print.jpg


    Sir!

    in my MySQL queries i mention only one number sir,,

    But if i wants to taken more then one number (for example: ("select EmployeeID from newemp where date = '"+2012/06/06"') )

    how to i set the printing option to take number of different employees salary slip

    and

    where & how to use loop in it..,

    Can you guide me please sir..,
    I am alway's waiting for your response sir..,
    Thank you..,

  4. #4
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Default Re: way to take printout from mysql

    Anyone can Guide me please..,
    I am waiting for your response sir..,
    Thank you..,

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: way to take printout from mysql

    I would do the database stuff prior to printing.
    Turn the data into a List<SomeClass> where SomeClass models the data in a row.
    Then call print on an object that contains this List.

    Your print() method then can simply access the entry in the List based on the 'page' number.
    This presumes each pay slip is a single page.
    Last edited by Tolls; 06-06-2012 at 01:43 PM. Reason: typos
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Default Re: way to take printout from mysql

    Thank you sir!
    Can you show me a simple example sir,
    I try now self..,

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: way to take printout from mysql

    You really need to try it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Default Re: way to take printout from mysql

    Thank You Sir!
    i will do myself ..,

  9. #9
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: way to take printout from mysql

    Just another route to get to, at least what I think, your requirements are: jasperreports : JasperForge

  10. #10
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    258
    Rep Power
    3

    Default Re: way to take printout from mysql

    thank you very much sir,
    in youtube i watch the videos sample for use jasperreports in web application now..,
    is it suitable for stand alone application sir?..,

  11. #11
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: way to take printout from mysql

    Quote Originally Posted by raj.mscking@gmail.com View Post
    is it suitable for stand alone application sir?..,
    I have never used it in that environment.

Similar Threads

  1. Replies: 4
    Last Post: 03-04-2012, 11:26 PM
  2. Jsp page printout not properly rendering in IE7
    By fdy in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-28-2011, 10:45 AM
  3. First image printout problem?
    By JimCrowell@EMail.com in forum Advanced Java
    Replies: 0
    Last Post: 04-23-2010, 07:05 PM
  4. mysql help
    By messi_fcb in forum JDBC
    Replies: 1
    Last Post: 03-27-2010, 09:56 PM
  5. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •