Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee", "root", "");
- PreparedStatement pt = connect.prepareStatement("INSERT INTO employee (firstname,lastname,deptcode,phoneno,hiredate,job) values(?,?,?,?,?,?)");
- pt.setString(1, fnameTField.getText());
- pt.setString(2, lnameTField.getText());
- pt.setString(3, deptCodeCombo.getSelectedItem().toString());
- pt.setString(4, phoneTField.getText());
- pt.setString(5, hiredateTField.getText());
- pt.setString(6, jobTField.getText());
- pt.executeUpdate();
- connect.close();
- JOptionPane.showMessageDialog(this, "New Employee Save!", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
- fnameTField.setText(null);
- lnameTField.setText(null);
- deptCodeCombo.setSelectedIndex(0);
- hiredateTField.setText(null);
- phoneTField.setText(null);
- jobTField.setText(null);
- NewRecord.setVisible(false);
- } catch (SQLException sqe) {
- JOptionPane.showMessageDialog(this, "SQl error!", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
- System.out.println("SQl error: " + sqe.toString());
- } catch (ClassNotFoundException cnf) {
- System.out.println("Class not found error: " + cnf.toString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement