0% found this document useful (0 votes)
25 views3 pages

Ja VA1

This Java code defines an exam class with methods to add exam data to a database table. It gets exam name, term, date and other fields from text boxes and combo boxes, sets them as parameters in a prepared statement, and executes the statement to insert a new exam record into the exam table. It also defines a main method to launch the exam user interface.

Uploaded by

kpegohe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Ja VA1

This Java code defines an exam class with methods to add exam data to a database table. It gets exam name, term, date and other fields from text boxes and combo boxes, sets them as parameters in a prepared statement, and executes the statement to insert a new exam record into the exam table. It also defines a main method to launch the exam user interface.

Uploaded by

kpegohe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

private void jButton1ActionPerformed(java.awt.event.

ActionEvent evt) {
// TODO add your handling code here:

String examname = txtename.getText();


String term = txtterm.getSelectedItem().toString();

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


String date = dfl.format(txtdate.getDate());

String classs = "";


if (txtclass.getSelectedItem() != null) {
classs = txtclass.getSelectedItem().toString();
}

String section = txtsection.getSelectedItem().toString();

String subject = txtsubject.getSelectedItem().toString();

try {
pst = con.prepareStatement("insert into
exam(ename,term,date,class,section,subject)Values(?,?,?,?,?,?)");

pst.setString(1,examname);
pst.setString(2,term);
pst.setString(3,date);
pst.setString(4,classs);
pst.setString(5,section);
pst.setString(6,subject);

pst.executeUpdate();
JOptionPane.showMessageDialog(this, "Exam Added");

} catch (SQLException ex) {


Logger.getLogger(Exam.class.getName()).log(Level.SEVERE, null, ex);
}

}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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(Exam.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Exam.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Exam.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Exam.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


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

// Variables declaration - do not modify


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.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JComboBox<String> txtclass;
private com.toedter.calendar.JDateChooser txtdate;
private javax.swing.JTextField txtename;
private javax.swing.JComboBox<String> txtsection;
private javax.swing.JComboBox<String> txtsubject;
private javax.swing.JComboBox<String> txtterm;
// End of variables declaration
}

You might also like