You are on page 1of 28

Registration Form Source Code

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class RegForm extends javax.swing.JFrame {

public RegForm() {
initComponents();
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
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();
Mname = new javax.swing.JLabel();
Lname = new javax.swing.JTextField();
Fname = new javax.swing.JTextField();
MidName = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
Snumber = new javax.swing.JTextField();
Eaddress = new javax.swing.JTextField();
Cnumber = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
Fathersname = new javax.swing.JTextField();
Mothersname = new javax.swing.JTextField();
CbSex = new javax.swing.JComboBox<>();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
CBCourse = new javax.swing.JComboBox<>();
CBYearLevel = new javax.swing.JComboBox<>();
CBSection = new javax.swing.JComboBox<>();
jLabel16 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
Paddress = new javax.swing.JTextArea();
BtnDb = new javax.swing.JButton();
BtnCancel = new javax.swing.JButton();
BtnReg = new javax.swing.JButton();
DcBday = new com.toedter.calendar.JDateChooser();
DcAdate = new com.toedter.calendar.JDateChooser();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ECST - REGISTRATION SYSTEM");

jPanel1.setBackground(new java.awt.Color(0, 255, 0));

jLabel1.setFont(new java.awt.Font("Segoe UI Black", 1, 18)); // NOI18N


jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("ECST - STUDENT REGISTRATION FORM");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);


jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(156, 156, 156)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addContainerGap())
);

jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel2.setText("FIRST NAME");

jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel3.setText("DATE OF BIRTH");

jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel4.setText("LAST NAME");

Mname.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


Mname.setText("MIDDLE NAME");

Lname.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
LnameKeyTyped(evt);
}
});

Fname.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
FnameKeyTyped(evt);
}
});

MidName.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
MidNameKeyTyped(evt);
}
});

jLabel6.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel6.setText("Student No.");

jLabel7.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel7.setText("Email Address");

jLabel8.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel8.setText("Admission Date");

jLabel9.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel9.setText("Contact Number");

Snumber.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SnumberActionPerformed(evt);
}
});
Snumber.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
SnumberKeyTyped(evt);
}
});
Eaddress.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EaddressActionPerformed(evt);
}
});

Cnumber.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CnumberActionPerformed(evt);
}
});
Cnumber.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
CnumberKeyTyped(evt);
}
});

jLabel10.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel10.setText("Mother's Maiden Name");

jLabel11.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel11.setText("Father's Name");

jLabel12.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel12.setText("Sex");
CbSex.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "MALE",
"FEMALE" }));

jLabel13.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel13.setText("Diploma Course");

jLabel14.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel14.setText("Year Level");

jLabel15.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel15.setText("Section");

CBCourse.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]


{ "INFORMATION TECHNOLOGY", "COMPUTER ENGINEERING TECHNOLOGY", "HOTEL &
RESTAURANT TECHNOLOGY", "TOURISM & TRAVEL MANAGEMENT TECHNOLOGY" }));

CBYearLevel.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1ST


YEAR", "2ND YEAR", "3RD YEAR", "4TH YEAR" }));

CBSection.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "IT -101",


"IT -102", "IT - 201", "IT - 202", "IT - 301", "IT - 302", "CET -101", "CET -102", "CET - 201", "CET -
202", "CET - 301", "CET - 302", "HRT -101", "HRT -102", "HRT -201", "HRT -202", "HRT -301",
"HRT -302", "TTMT -101", "TTMT -102", "TTMT - 201", "TTMT - 202", "TTMT - 301", "TTMT -
302", " ", " ", " " }));

jLabel16.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


jLabel16.setText("PERMANENT ADDRESS");

Paddress.setColumns(20);
Paddress.setRows(5);
jScrollPane1.setViewportView(Paddress);

BtnDb.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


BtnDb.setText("DATABASE");
BtnDb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnDbActionPerformed(evt);
}
});

BtnCancel.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


BtnCancel.setText("CANCEL");
BtnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnCancelActionPerformed(evt);
}
});

BtnReg.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


BtnReg.setText("REGISTER");
BtnReg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnRegActionPerformed(evt);
}
});

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.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(BtnReg)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BtnDb)
.addGap(179, 179, 179)
.addComponent(BtnCancel)
.addGap(76, 76, 76))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(jLabel13)
.addComponent(jLabel16)
.addComponent(CBCourse, javax.swing.GroupLayout.PREFERRED_SIZE, 178,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 98, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
TRAILING, false)
.addComponent(Cnumber, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
.addComponent(Lname, javax.swing.GroupLayout.Alignment.LEADING))
.addComponent(jLabel9)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 68,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Fname, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(Snumber, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(jLabel11)
.addComponent(Fathersname, javax.swing.GroupLayout.PREFERRED_SIZE,
178, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jLabel10)
.addComponent(jLabel14)
.addComponent(Mothersname, javax.swing.GroupLayout.PREFERRED_SIZE,
189, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CBYearLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 115,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(Mname)
.addComponent(MidName, javax.swing.GroupLayout.PREFERRED_SIZE,
100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(Eaddress, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRA
ILING)
.addComponent(jLabel3)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(DcAdate, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CbSex, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel15)
.addComponent(CBSection, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(1, 1, 1)
.addComponent(DcBday, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(57, 57, 57))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Mname, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(Lname, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Fname, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(MidName, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(DcBday, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Eaddress, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Mothersname, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CbSex, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(DcAdate, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(Cnumber, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Snumber, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Fathersname, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE,
false)
.addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 27,
Short.MAX_VALUE)
.addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(CBCourse, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CBYearLevel, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CBSection, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addComponent(BtnCancel, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BtnReg, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(BtnDb, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void EaddressActionPerformed(java.awt.event.ActionEvent evt) {

private void SnumberActionPerformed(java.awt.event.ActionEvent evt) {

private void BtnDbActionPerformed(java.awt.event.ActionEvent evt) {


DATABASE df = new DATABASE ();
df.setVisible(true);
}

private void BtnRegActionPerformed(java.awt.event.ActionEvent evt) {


int get = JOptionPane.showConfirmDialog(this, "SAVE IN THE DATABASE?","SELECT AN
OPTION", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (get == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(this, "REGISTRATION SAVED!");

}
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/studdb","root","Qwerty12");
String sql = "insert into studdbtable values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1,(Lname.getText()));
pstmt.setString(2, Fname.getText());
pstmt.setString(3, MidName.getText());

SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");


String Birthday = dateformat.format(DcBday.getDate());
pstmt.setString (4, Birthday);
pstmt.setInt(5, Integer.parseInt(Cnumber.getText()));
pstmt.setInt(6, Integer.parseInt(Snumber.getText()));
pstmt.setString(7, Eaddress.getText());

String AdmiDate = dateformat.format(DcAdate.getDate());


pstmt.setString (8, AdmiDate);

pstmt.setString(9, Fathersname.getText());
pstmt.setString(10, Mothersname.getText());

String sex;
sex = CbSex.getSelectedItem().toString();
pstmt.setString(11, sex);
String course;
course = CBCourse.getSelectedItem().toString();
pstmt.setString(12, course);
String yearlevel;
yearlevel = CBYearLevel.getSelectedItem().toString();
pstmt.setString(13, yearlevel);
String sec;
sec = CBSection.getSelectedItem().toString();
pstmt.setString(14, sec);
pstmt.setString(15, Paddress.getText());
pstmt.executeUpdate();
JOptionPane.showMessageDialog(null, "insertion successfull");
conn.close();

}catch(Exception e){

JOptionPane.showMessageDialog(null, e);
}

private void BtnCancelActionPerformed(java.awt.event.ActionEvent evt) {


Lname.setText("");
Fname.setText("");
MidName.setText("");

Cnumber.setText("");
Snumber.setText("");
Eaddress.setText("");

Fathersname.setText("");
Mothersname.setText("");

Paddress.setText("");
CBYearLevel.setSelectedIndex(0);
CBSection.setSelectedIndex(0);

private void CnumberKeyTyped(java.awt.event.KeyEvent evt) {


char j = evt.getKeyChar();
if(Character.isLetter(j)){
evt.consume();
}
}

private void SnumberKeyTyped(java.awt.event.KeyEvent evt) {


char j = evt.getKeyChar();
if(Character.isLetter(j)){
evt.consume();
}
}

private void CnumberActionPerformed(java.awt.event.ActionEvent evt) {

private void LnameKeyTyped(java.awt.event.KeyEvent evt) {


char j = evt.getKeyChar();
if(Character.isLetter(j)){
evt.consume();
}
}

private void FnameKeyTyped(java.awt.event.KeyEvent evt) {


char j = evt.getKeyChar();
if(Character.isLetter(j)){
evt.consume();
}
}

private void MidNameKeyTyped(java.awt.event.KeyEvent evt) {


char j = evt.getKeyChar();
if(Character.isLetter(j)){
evt.consume();
}
}
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RegForm().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton BtnCancel;
private javax.swing.JButton BtnDb;
private javax.swing.JButton BtnReg;
private javax.swing.JComboBox<String> CBCourse;
private javax.swing.JComboBox<String> CBSection;
private javax.swing.JComboBox<String> CBYearLevel;
private javax.swing.JComboBox<String> CbSex;
private javax.swing.JTextField Cnumber;
private com.toedter.calendar.JDateChooser DcAdate;
private com.toedter.calendar.JDateChooser DcBday;
private javax.swing.JTextField Eaddress;
private javax.swing.JTextField Fathersname;
private javax.swing.JTextField Fname;
private javax.swing.JTextField Lname;
private javax.swing.JTextField MidName;
private javax.swing.JLabel Mname;
private javax.swing.JTextField Mothersname;
private javax.swing.JTextArea Paddress;
private javax.swing.JTextField Snumber;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}

Database Source Code


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

public class DATABASE extends javax.swing.JFrame {


Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;

public DATABASE() {
initComponents();
showData();
}
public void showData(){

try {
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/studdb","root","Qwerty12");
String q;
q = "select * from studdbtable";
pst = con.prepareStatement(q);
rs = pst.executeQuery();
StudTable.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex);
}
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel2 = new javax.swing.JPanel();


jLabel1 = new javax.swing.JLabel();
BtnBack = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
StudTable = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("DATABASE");

jPanel2.setBackground(new java.awt.Color(0, 255, 0));

jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N


jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("ECST - STUDENT REGISTRATION SYSTEM");

BtnBack.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N


BtnBack.setText("BACK");
BtnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnBackActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);


jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(BtnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 62,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 341,
Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(248, 248, 248))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BtnBack))
.addContainerGap())
);

StudTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {

},
new String [] {
"Last Name", "Fist Name", "Middle Name", "Birthday", "Contact Number", "Student
No.", "Email Address", "Admission Date", "Father's Name", "Mother's Name", "Sex", "Diploma
Course", "Year ", "Section", "Address"
}
));
jScrollPane1.setViewportView(StudTable);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 572,
Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

private void BtnBackActionPerformed(java.awt.event.ActionEvent evt) {


this.setVisible(false);

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DATABASE().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton BtnBack;
private javax.swing.JTable StudTable;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}

You might also like