Results 1 to 11 of 11
Thread: way to take printout from mysql
- 06-05-2012, 01:14 PM #1
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
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)

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.
- 06-05-2012, 05:26 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 697
- Rep Power
- 6
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.
Website: Learn Java by Examples
- 06-06-2012, 08:25 AM #3
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
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)

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..,
- 06-06-2012, 01:30 PM #4
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: way to take printout from mysql
Anyone can Guide me please..,
I am waiting for your response sir..,
Thank you..,
- 06-06-2012, 01:43 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 06-06-2012, 03:03 PM #6
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: way to take printout from mysql
Thank you sir!
Can you show me a simple example sir,
I try now self..,
- 06-06-2012, 03:49 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: way to take printout from mysql
You really need to try it.
Please do not ask for code as refusal often offends.
- 06-07-2012, 03:03 AM #8
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: way to take printout from mysql
Thank You Sir!
i will do myself ..,
- 06-07-2012, 04:00 AM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Re: way to take printout from mysql
Just another route to get to, at least what I think, your requirements are: jasperreports : JasperForge
- 06-07-2012, 04:42 AM #10
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
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?..,
- 06-07-2012, 04:52 AM #11
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Similar Threads
-
Is this a java issue? JApplet with MySQL access.. can't connect to mySQL
By cplredhartsock in forum Java AppletsReplies: 4Last Post: 03-04-2012, 11:26 PM -
Jsp page printout not properly rendering in IE7
By fdy in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-28-2011, 10:45 AM -
First image printout problem?
By JimCrowell@EMail.com in forum Advanced JavaReplies: 0Last Post: 04-23-2010, 07:05 PM -
mysql help
By messi_fcb in forum JDBCReplies: 1Last Post: 03-27-2010, 09:56 PM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 01:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks