<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<table style="text-align: left; width: 946px; height: 600px;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top;"><big style="color: rgb(0, 51, 51);"><big><big><span style="font-weight: bold;"><span style="font-family: Times New Roman, Times, serif;">DIEUTEK </span> </span> </big> </big> </big><span style="font-weight: bold; color: rgb(0, 51, 51);"><span style="font-family: Times New Roman, Times, serif;">DEVELOPMENTS</span> </span><br></td> <td style="vertical-align: top;"><br></td> </tr> <tr> <td colspan="2" rowspan="1" style="vertical-align: top; width: 25%; height: 25%; color: rgb(51, 51, 255); background-color: rgb(0, 51, 51);"><img style="width: 412px; height: 252px;" alt="hghgh" src="file:///home/dieutek/Desktop/3193292.jpg"><big><big><big><span style="font-weight: bold;"><span style="font-family: Times New Roman, Times, serif;"></span> </span> </big> </big> </big><big><big><big><span style="font-weight: bold;"><span style="font-family: Times New Roman, Times, serif;"></span> </span> </big> </big> </big><big><big><big><span style="font-weight: bold;"><span style="font-family: Times New Roman, Times, serif;"> </span> </span> </big><big style="color: rgb(0, 102, 0);"><big><span style="font-family: Times New Roman, Times, serif;"><small>Tailored Innovations.Timely Service</small> </span> </big> </big> </big> </big><br></td> </tr> <tr> <td style="vertical-align: top; width: 25%;"><br> <a style="color:rgb(0,102,0);" href="MgrAttendance.jsp">Attendance</a><br> <a style="color:rgb(0,102,0);" href="MgrLeave.jsp">Leave</a><br> <a style="color:rgb(0,102,0);" href="">Add/Edit Employees</a><br> </td> </tr> </table>
this is my jsp page
package servlet; import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; import java.sql.*; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date;
public class employeeInformation {
int insertion; JFrame f; JPanel p1,p2,p3,p4; JTabbedPane tp; JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,l16,l17,l18,l19,l20,l21,l22,l23,l24,l25,l26,l27,l28,l29,l30,l31,l32,l33,l34,l35,l36,l37,l38,l39; JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12,tf13,tf14,tf15,tf16,tf17,tf18,tf19,tf20,tf21,tf22,tf23,tf24,tf25,tf26,tf27,tf28,tf29,tf30,tf31,tf32,tf33,tf34,tf35,tf36,tf37,tf38; JButton insert,reset,view,edit,delete; SimpleDateFormat s; employeeInformation(){ f=new JFrame("Form"); p1=new JPanel(new GridLayout(12,2)); p2=new JPanel(new GridLayout(2,2)); p3=new JPanel(new GridLayout(12,2)); p4=new JPanel(new GridLayout(12,2)); tp=new JTabbedPane(); s=new SimpleDateFormat(); s.applyPattern("dd/mm/yyyy");
//insertion
l1=new JLabel("Employee ID:");
l2=new JLabel("Employee First Name:");
l3=new JLabel("Employee Last Name:");
l4=new JLabel("Employee Address:");
l5=new JLabel("Job ID:");
l6=new JLabel("Phones:");
l7=new JLabel("Salary:");
l8=new JLabel("Email:");
l9=new JLabel("Sex:");
l10=new JLabel("Qualification:");
l11=new JLabel("DOB:");
l12=new JLabel("Hire Date:");
//deletion
l13=new JLabel("Employee ID:");
//edition
//l14=new JLabel("Employee ID:");
l15=new JLabel("Employee ID:"); l16=new JLabel("Employee First Name:"); l17=new JLabel("Employee Last Name:"); l18=new JLabel("Employee Address:"); l19=new JLabel("Job ID:"); l20=new JLabel("Phones:"); l21=new JLabel("Salary:"); l22=new JLabel("Email:"); l23=new JLabel("Sex:"); l24=new JLabel("Qualification:"); l25=new JLabel("DOB:"); l26=new JLabel("Hire Date:");
//selection l39=new JLabel("Enter employee ID you want to recieve:"); l27=new JLabel("Enter Employee ID:"); l28=new JLabel("Employee First Name:"); l29=new JLabel("Employee Last Name:"); l30=new JLabel("Employee Address:"); l31=new JLabel("Job ID:"); l32=new JLabel("Phones:"); l33=new JLabel("Salary:"); l34=new JLabel("Email:"); l35=new JLabel("Sex:"); l36=new JLabel("Qualification:"); l37=new JLabel("DOB:"); l38=new JLabel("Hire Date:");
//insertion tf1=new JTextField(25); tf2=new JTextField(25); tf3=new JTextField(25); tf4=new JTextField(25); tf5=new JTextField(25); tf6=new JTextField(25); tf7=new JTextField(25); tf8=new JTextField(25); tf9=new JTextField(25); tf10=new JTextField(25); tf11=new JTextField(25); tf12=new JTextField(25);
//deletion
tf13=new JTextField(25);
// edition //tf14=new JTextField(25); tf15=new JTextField(25); tf16=new JTextField(25); tf17=new JTextField(25); tf18=new JTextField(25); tf19=new JTextField(25); tf20=new JTextField(25); tf21=new JTextField(25); tf22=new JTextField(25); tf23=new JTextField(25); tf24=new JTextField(25); tf25=new JTextField(25); tf26=new JTextField(25);
//selection tf27=new JTextField(25); tf28=new JTextField(25); tf29=new JTextField(25); tf30=new JTextField(25); tf31=new JTextField(25); tf32=new JTextField(25); tf33=new JTextField(25); tf34=new JTextField(25); tf35=new JTextField(25); tf36=new JTextField(25); tf37=new JTextField(25); tf38=new JTextField(25);
//buttons
insert=new JButton("Add ");
reset=new JButton("Reset");
view=new JButton("view");
edit=new JButton("Save");
delete=new JButton("Delete");
//insertion
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(l5);
p1.add(tf5);
p1.add(l6);
p1.add(tf6);
p1.add(l7);
p1.add(tf7);
p1.add(l8);
p1.add(tf8);
p1.add(l9);
p1.add(tf9);
p1.add(l10);
p1.add(tf10);
p1.add(l11);
p1.add(tf11);
p1.add(l12);
p1.add(tf12);
p1.add(insert); //p1.add(reset);
//deletion
p2.add(l13);
p2.add(tf13);
p2.add(delete);
//selection
//p3.add(l14);
//p3.add(tf14);
p3.add(l15);
p3.add(tf15);
p3.add(l16);
p3.add(tf16);
p3.add(l17);
p3.add(tf17);
p3.add(l18);
p3.add(tf18);
p3.add(l19);
p3.add(tf19);
p3.add(l20);
p3.add(tf20);
p3.add(l21);
p3.add(tf21);
p3.add(l22);
p3.add(tf22);
p3.add(l23);
p3.add(tf23);
p3.add(l24);
p3.add(tf24);
p3.add(l25);
p3.add(tf25);
p3.add(l26);
p3.add(tf26);
p3.add(edit); p3.add(reset); // p4.add(l39); p4.add(l27); p4.add(tf27); p4.add(l28); p4.add(tf28); p4.add(l29); p4.add(tf29); p4.add(l30); p4.add(tf30); p4.add(l31); p4.add(tf31); p4.add(l32); p4.add(tf32); p4.add(l33); p4.add(tf33); p4.add(l34); p4.add(tf34); p4.add(l35); p4.add(tf35); p4.add(l37); p4.add(tf37); p4.add(l38); p4.add(tf38); p4.add(view); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ tf1.setText(""); tf2.setText(""); tf3.setText(""); tf4.setText(""); tf5.setText(""); tf6.setText(""); tf7.setText(""); tf8.setText(""); tf9.setText(""); tf10.setText(""); tf11.setText(""); tf12.setText(""); tf13.setText(""); } }); insert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ String t1=tf1.getText(); String t2=tf2.getText(); String t3=tf3.getText(); String t4=tf4.getText(); String t5=tf5.getText(); String t6=tf6.getText(); String t7=tf7.getText(); String t8=tf8.getText(); String t9=tf9.getText(); String t10=tf10.getText(); String t11=tf11.getText(); String t12=tf12.getText(); try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","root", "1"); Statement s=con.createStatement(); insertion = s.executeUpdate("insert into employee(emp_id,emp_fname,emp_lname,emp_address,job_id,salary,phone,email,sex,qualification,dob,hiredate) values('"+t1+"', '"+t2+"' ,'"+t3+"' , '"+t4+"' ,'"+t5+"', '"+t6+"' ,'"+t7+"' , '"+t8+"' ,'"+t9+"', '"+t10+"' ,'"+t11+"' , '"+t12+"')"); JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database."); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(p1,"Error in submitting data!"); } } }); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ String t1=tf13.getText(); try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","root", "1"); PreparedStatement ps=con.prepareStatement("DELETE FROM employee WHERE emp_id = ?"); ps.setString(1,t1); ps.executeUpdate(); JOptionPane.showMessageDialog(p2,"Record is deleted successfully."); con.close(); } catch(Exception exp3) { JOptionPane.showMessageDialog(p2,"Error in deleting record."); } } }); view.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ String t2=tf27.getText(); try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","root", "1"); PreparedStatement st=con.prepareStatement("select * from employee where emp_id=?"); st.setString(1,t2); ResultSet rs=st.executeQuery(); while(rs.next()){ tf27.setText(Integer.toString(rs.getInt(1))); tf28.setText(rs.getString(2)); tf29.setText(rs.getString(3)); tf30.setText(rs.getString(4)); tf31.setText(Integer.toString(rs.getInt(5))); tf32.setText(Integer.toString(rs.getInt(6))); tf33.setText(Integer.toString(rs.getInt(7))); tf34.setText(rs.getString(8)); tf35.setText(rs.getString(9)); tf36.setText(rs.getString(10)); tf37.setText(s.format(new Date())); tf38.setText(s.format(new Date())); } con.close(); }catch(Exception e) { JOptionPane.showMessageDialog(p4,"Cannot Display data"); } } }); edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ try { int x=JOptionPane.showConfirmDialog(p3,"Confirm edit? All data will be replaced"); if(x==0){ try{ String val1=tf14.getText(); String val2=tf15.getText(); String val3=tf16.getText(); String val4=tf17.getText(); String val5=tf18.getText(); String val6=tf19.getText(); String val7=tf20.getText(); String val8=tf21.getText(); String val9=tf22.getText(); String val10=tf23.getText(); String val11=tf24.getText(); String val12=tf25.getText(); Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","root", "1"); Statement st=con.createStatement(); st.executeUpdate("update employee set emp_id='"+val1+"', emp_fname='"+val2+"', emp_lname='"+val3+"' , emp_address'"+val4+"', job_id='"+val5+"', salary='"+val6+"' , phone='"+val7+"' , email='"+val8+"', sex='"+val9+"', qualification='"+val10+"' , dob='"+val11+"', hiredate='"+val12+"' where emp_id='"+val1+"'"); JOptionPane.showMessageDialog(p3,"Updated successfully"); con.close(); con.close(); } catch(Exception ex) { JOptionPane.showMessageDialog(p3,"Error in updating edit fields"); } } } catch(Exception ex) { JOptionPane.showMessageDialog(p3,"Error"); } } }); } public void display() { f.getContentPane().add(tp); tp.addTab("Add Record", p1); tp.addTab("Delete Record", p2); tp.addTab("View Record", p4); tp.addTab("Edit Record", p3); f.setSize(500,500); f.setVisible(true); f.setResizable(true); } public static void main(String ar[]){ employeeInformation inf=new employeeInformation(); inf.display(); } }
this is my java page.how to connect these two pages.
Ads