AJP Project
AJP Project
HeadlessException;
import java.sql.*;
import javax.swing.JOptionPane;
public class addAdmin extends javax.swing.JFrame {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public addAdmin() {
super("Add Admin");
initComponents();
conn=databaseConnection.connection();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
name = new javax.swing.JTextField();
mail = new javax.swing.JTextField();
password = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new
javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED
), "Admin Sign Up",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new
java.awt.Font("Times New Roman", 1, 24)));
jLabel1.setText("Name");
jLabel2.setText("Email");
jLabel3.setText("Password");
name.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nameActionPerformed(evt);
}
});
jButton1.setText("Submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Back");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(40, 40, 40)
.addComponent(name))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2))
.addComponent(password)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(42, 42, 42)
.addComponent(mail, javax.swing.GroupLayout.PREFERRED_SIZE, 150,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(49, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel1)
.addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel2)
.addComponent(mail, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel3)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(21, Short.MAX_VALUE))
);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Home");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Logout");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(316, 317));
setLocationRelativeTo(null);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Home object =new Home();
object.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Login object =new Login();
object.setVisible(true);
}
private void nameActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt=conn.createStatement();
String adminName=name.getText();
String adminMail=mail.getText();
String adminPass=password.getText();
String sql="INSERT INTO ADMIN(mail, password, name)
values('"+adminMail+"', '"+adminPass+"', '"+adminName+"')";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Data inserted Successfully");
}catch(SQLException | HeadlessException e)
{JOptionPane.showMessageDialog(null,e);}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Login object =new Login();
object.setVisible(true);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(addAdmin.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(addAdmin.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(addAdmin.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(addAdmin.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(() -> {
new addAdmin().setVisible(true);
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField mail;
private javax.swing.JTextField name;
private javax.swing.JPasswordField password;
}
import java.awt.HeadlessException;
import java.sql.*;
import javax.swing.JOptionPane;
public class Login extends javax.swing.JFrame {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Login() {
super("Login");
initComponents();
conn=databaseConnection.connection();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
password = new javax.swing.JPasswordField();
email = new javax.swing.JTextField();
login = new javax.swing.JButton();
cancel = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 51));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new
javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED
), "Login Page",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new
java.awt.Font("Times New Roman", 1, 24))); // NOI18N
jPanel1.setToolTipText("");
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel1.setText("Email");
jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel2.setText("Password");
password.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
passwordActionPerformed(evt);
}
});
login.setFont(new java.awt.Font("Times New Roman", 3, 16)); // NOI18N
login.setText("Login");
login.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginActionPerformed(evt);
}
});
cancel.setFont(new java.awt.Font("Times New Roman", 3, 16)); // NOI18N
cancel.setText("Cancel");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelActionPerformed(evt);
}
});
jLabel3.setForeground(new java.awt.Color(0, 0, 255));
jLabel3.setText("Sign Up");
jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel3MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(151, 151, 151)
.addComponent(jLabel3))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.
addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATE
D)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(login)
.
addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATE
D)
.addComponent(cancel))
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addComponent(email)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 161,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(81, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel1)
.addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(login)
.addComponent(cancel))
.
addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATE
D)
.addComponent(jLabel3)
.addContainerGap(27, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(374, 291));
setLocationRelativeTo(null);
}
private void passwordActionPerformed(java.awt.event.ActionEvent evt) {
}
private void loginActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt =conn.createStatement();
String userEmail=email.getText();
String userPass=password.getText();
String sql="SELECT * FROM admin WHERE mail='"+userEmail+"' &&
password='"+userPass+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
setVisible(false);
Home object =new Home();
object.setVisible(true);
}else{
JOptionPane.showMessageDialog(null,"Password or email is invalid");
}
}catch(SQLException | HeadlessException e){
JOptionPane.showMessageDialog(null,e);
}
}
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {
setVisible(false);
addAdmin object =new addAdmin();
object.setVisible(true);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(() -> {
new Login().setVisible(true);
});
}
private javax.swing.JButton cancel;
private javax.swing.JTextField email;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton login;
private javax.swing.JPasswordField password;
}
import java.sql.*;
import javax.swing.JOptionPane;
public class addStudent extends javax.swing.JFrame {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public addStudent() {
super("Add Student");
initComponents();
conn=databaseConnection.connection();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
Name = new javax.swing.JTextField();
fatherName = new javax.swing.JTextField();
city = new javax.swing.JTextField();
blood = new javax.swing.JComboBox();
phone = new javax.swing.JTextField();
stdClass = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Add
New Student", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new
java.awt.Font("Times New Roman", 1, 24))); // NOI18N
jLabel1.setText("Name");
jLabel2.setText("Father's Name");
jLabel3.setText("City");
jLabel4.setText("Blood");
jLabel5.setText("Phone");
jLabel6.setText("Sem");
city.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cityActionPerformed(evt);
}
});
blood.setModel(new javax.swing.DefaultComboBoxModel(new String[]
{ "A+ve", "A-ve", "B+ve", "B-ve", "O+ve", "O-ve", "AB+ve", "AB-ve", " " }));
phone.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
phoneActionPerformed(evt);
}
});
jButton1.setText("Submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Back");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(48, 48, 48)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(21, 21, 21)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addComponent(Name)
.addComponent(fatherName)
.addComponent(city)
.addComponent(blood, 0, 141, Short.MAX_VALUE)
.addComponent(phone)
.addComponent(stdClass))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2)))
.addContainerGap(88, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel1)
.addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel2)
.addComponent(fatherName, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel3)
.addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel4)
.addComponent(blood, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel5)
.addComponent(phone, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel6)
.addComponent(stdClass, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(41, Short.MAX_VALUE))
);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Home");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Logout");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(420, 468));
setLocationRelativeTo(null);
}
private void cityActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Home object =new Home();
object.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Login object =new Login();
object.setVisible(true);
}
private void phoneActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt=conn.createStatement();
String stdName = Name.getText();
String stdBlood =(String) blood.getSelectedItem();
String stdFather=fatherName.getText();
String stdCity=city.getText();
String stdPhone=phone.getText();
int stdclass =Integer.parseInt(stdClass.getText());
String sql ="INSERT INTO STUDENT(stdName, stdFatherName, stdBlood,
stdCity, stdPhone, class) VALUES('"+stdName+"','"+stdFather+"',
'"+stdBlood+"', '"+stdCity+"', '"+stdPhone+"', '"+stdclass+"' )";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Data is Successfully inserted");
}catch(SQLException | NumberFormatException e){
JOptionPane.showMessageDialog(null,e);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Home object =new Home();
object.setVisible(true);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(addStudent.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(addStudent.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(addStudent.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(addStudent.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(() -> {
new addStudent().setVisible(true);
});
}
private javax.swing.JTextField Name;
private javax.swing.JComboBox blood;
private javax.swing.JTextField city;
private javax.swing.JTextField fatherName;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField phone;
private javax.swing.JTextField stdClass;
}
import java.sql.*;
import javax.swing.JOptionPane;
public class student extends javax.swing.JFrame {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public student() {
super("Student Registration System");
initComponents();
conn=databaseConnection.connection();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
id = new javax.swing.JTextField();
fatherName = new javax.swing.JTextField();
city = new javax.swing.JTextField();
phone = new javax.swing.JTextField();
stdClass = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
blood = new javax.swing.JTextField();
Name = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Update
or Delete", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new
java.awt.Font("Times New Roman", 1, 24))); // NOI18N
jLabel1.setText("Name");
jLabel2.setText("Father's Name");
jLabel3.setText("City");
jLabel4.setText("Blood");
jLabel5.setText("Phone");
jLabel6.setText("Sem");
city.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cityActionPerformed(evt);
}
});
phone.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
phoneActionPerformed(evt);
}
});
jButton1.setText("Update");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Back");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Search");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Delete");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jLabel7.setText("Id");
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(48, 48, 48)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addGap(21, 21, 21)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addComponent(id, javax.swing.GroupLayout.DEFAULT_SIZE, 141,
Short.MAX_VALUE)
.addComponent(fatherName)
.addComponent(city)
.addComponent(phone)
.addComponent(stdClass)
.addComponent(blood)
.addComponent(Name))
.
addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATE
D)
.addComponent(jButton3))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(93, 93, 93)
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton4)
.addGap(18, 18, 18)
.addComponent(jButton2)))
.addContainerGap(18, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(42, 42, 42)
.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
16, Short.MAX_VALUE)
.addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel2)
.addComponent(fatherName, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel3)
.addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel4)
.addComponent(blood, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel5)
.addComponent(phone, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel6)
.addComponent(stdClass, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton4)
.addComponent(jButton1))
.addContainerGap(19, Short.MAX_VALUE))
);
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Home");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Logout");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
setSize(new java.awt.Dimension(418, 451));
setLocationRelativeTo(null);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Home object =new Home();
object.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Login object =new Login();
object.setVisible(true);
}
private void cityActionPerformed(java.awt.event.ActionEvent evt) {
}
private void phoneActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt=conn.createStatement();
int stdid=Integer.parseInt(id.getText());
String stdName = id.getText();
String stdBlood = blood.getText();
String stdFather=fatherName.getText();
String stdCity=city.getText();
String stdPhone=phone.getText();
int stdclass =Integer.parseInt(stdClass.getText());
String sql ="UPDATE STUDENT SET stdName='"+stdName+"',
stdFatherName='"+stdFather+"', stdBlood='"+stdBlood+"',
stdCity='"+stdCity+"', stdPhone='"+stdPhone+"', clasS='"+stdclass+"' WHERE
id='"+stdid+"'";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Data is Successfully updated");
}catch(SQLException | NumberFormatException e){
JOptionPane.showMessageDialog(null,e);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
Home object =new Home();
object.setVisible(true);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt=conn.createStatement();
int stdId=Integer.parseInt(id.getText());
String sql="SELECT * FROM STUDENT WHERE id= '"+stdId+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
Name.setText(rs.getString("stdName"));
fatherName.setText(rs.getString("stdFatherName"));
city.setText(rs.getString("stdCity"));
blood.setText(rs.getString("stdBlood"));
phone.setText(rs.getString("stdPhone"));
stdClass.setText(String.format("%s",rs.getInt("class")));
}else{
JOptionPane.showMessageDialog(null,"Record not Found");
}
}catch(SQLException | NumberFormatException e)
{JOptionPane.showMessageDialog(null,e);}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
try{
stmt=conn.createStatement();
int stdId=Integer.parseInt(id.getText());
String sql="DELETE FROM STUDENT WHERE id='"+stdId+"'";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"Data Deleted");
} catch (SQLException ex) {
}
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(student.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(student.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(student.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(student.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(() -> {
new student().setVisible(true);
});
}
private javax.swing.JTextField Name;
private javax.swing.JTextField blood;
private javax.swing.JTextField city;
private javax.swing.JTextField fatherName;
private javax.swing.JTextField id;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField phone;
private javax.swing.JTextField stdClass;
}