I am entering two employees data so dynamically I am getting two tables e1 and e2 and on those tables I am storing attendance of particular employee.See the below tables ,Here date column type is date. two tables e1 and e2,
|------------------||-----------------|
| date | present|| date | present|
|2015-9-7 | 1 ||2015-9-7| 1 |
|2015-9-8 | 1 ||2015-9-8| 0 |
|2015-9-9 | 1 ||2015-9-9| 1 |
To get the employee attendance, i have one text field to enter employee Id and I have two drop down list to choose dates i.e "dayfrom" shows 1,2..31 and "monthfrom" shows Jan,Feb..Dec and den samew another two drop down list "dayto" and "monthto".
so, my code is,
JTextField day1,day2,id;
Container c;
int t=0,in=0,re;
Integer mo1=new Integer(0);
Integer mo2=new Integer(0);
JButton sh,home,sha;
JLabel lday1,lday2,lid;
String tp;
String mo[]={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
int it[]=new int[100];
int ct[]=new int[100];
Choice dob1,dob2,add1,add2;
JOptionPane jp = new JOptionPane();
public emp()// constructor
{
lid = new JLabel("Id :");
lid.setForeground(Color.black);
lday1 = new JLabel("Day From :");
lday1.setForeground(Color.black);
lday2 = new JLabel("Day To:");
lday2.setForeground(Color.black);
id = new JTextField();
id.setForeground(Color.black);
id.setBackground(Color.white);
day1 = new JTextField();
day1.setForeground(Color.black);
day1.setBackground(Color.white);
day2 = new JTextField();
day2.setForeground(Color.black);
day2.setBackground(Color.white);
sh = new JButton("Show");
sh.setForeground(Color.white);
sh.setBackground(new Color(128,0,0));
dob1 = new Choice();
dob2 = new Choice();
dob1.add("1");
dob1.add("2");
dob1.add("3");
dob1.add("4");
dob1.add("5");
dob1.add("6");
dob1.add("7");
dob1.add("8");
dob2.add("JAN");
dob2.add("FEB");
dob2.add("MAR");
dob2.add("APR");
dob2.add("MAY");
dob1.setBounds(190,150,40,20);
dob2.setBounds(250,150,55,20);
add1 = new Choice();
add2 = new Choice();
add1.add("1");
add1.add("2");
add1.add("3");
add1.add("4");
add1.add("5");
add1.add("6");
add1.add("7");
add1.add("8");
add2.add("JAN");
add2.add("FEB");
add2.add("MAR");
add2.add("APR");
add2.add("MAY");
c.add(lid);
c.add(lday1);
c.add(lday2);
c.add(id);
c.add(sh);
c.add(dob1);
c.add(dob2);
c.add(add1);
c.add(add2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
Object source = ae.getSource();
if(source==sh)
{
re=0;
if((id.getText()).length()!=0)
{
try
{
t=0;
for(in=0;in<12;in++)
{
if(mo[in]==dob2.getSelectedItem())
mo1=in+1;
}
ResultSet rs = stm.executeQuery("select * from e"+id.getText()+" where date_format(day,'%d')="+dob1.getSelectedItem()+" and date_format(day,'%m')="+mo1);
while(rs.next())
{
t=1;
re=rs.getInt("pre");
if(re==1)
jp.showMessageDialog(this,"Present";
else
jp.showMessageDialog(this,"Absent");
}
if(t==0)
{
jp.showMessageDialog(this,"Sorry, No Such Record exists");
t=0;
}
}
}
But here I am getting output as "no such record exists".