Press "Enter" to skip to content

Add new student code of library management system.

Adding student is very important for any library management system. Because after register a student he/she can take any kind of book from library. But without register it is not possible in modern library management system.

So, it is very important issue…

To get help you can see the video.

Source code for add new student in library page.

  1. Connect with connection class…
Connection con = null;
ResultSet rs;
PreparedStatement pst;

public New_Student() {
initComponents();
con = Connect.dbConnect();
middle();
}

public void middle(){
setLocationRelativeTo(null);
}

2. Add new student code…

try{
if(jTextField1.getText().equals("") || jTextField2.getText().equals("") || jTextField3.getText().equals("") || jTextField4.getText().equals("")){
JOptionPane.showMessageDialog(null, "Field Must Not Empty !!!");
}else{
String sql = "select Student_ID from student where Student_ID = ?";
pst = con.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
rs = pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(null, jTextField1.getText()+" This Student ID Already Exists...!!!");
}else{
String sql1 = "insert into student(Student_ID,Name,Father,Course,Branch,Year,Semester) values(?,?,?,?,?,?,?)";
pst = con.prepareStatement(sql1);
pst.setString(1, jTextField1.getText());
pst.setString(2, jTextField2.getText());
pst.setString(3, jTextField3.getText());
pst.setString(4, (String) jComboBox1.getSelectedItem());
pst.setString(5, jTextField4.getText());
pst.setString(6, (String) jComboBox2.getSelectedItem());
pst.setString(7, (String) jComboBox3.getSelectedItem());
pst.execute();
JOptionPane.showMessageDialog(null, "Successfully Inserted...!!!");
}
}
}catch(HeadlessException | SQLException e){
JOptionPane.showMessageDialog(null, e);
}

Interface of after run the add new student page.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *