import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; public class Registration extends JApplet implements ActionListener { JFrame frame; JPanel panel; JButton Store; JLabel labelFName; JLabel labelLName; JLabel labelAddress; JLabel labelAccType; JLabel labelPhone; JLabel labelAnnualIncome; JTextField textFName; JTextField textLName; JTextField textAddress; JComboBox comboAccType; JTextField textPhone; JTextField textAnnualIncome; GridBagLayout g1; GridBagConstraints gbc; String[] AccType={"Saving","Current","Credit"}; public static void main(String args[]) { new Registration(); } public Registration() { panel = new JPanel(); frame=new JFrame("Customer Registration"); frame.setSize(400,200); frame.setVisible(true); frame.getContentPane().add(panel); g1 = new GridBagLayout(); gbc=new GridBagConstraints(); panel=(JPanel)getContentPane(); panel.setLayout(g1); Store = new JButton("Store"); labelFName = new JLabel("First Name"); labelLName = new JLabel("Last Name"); labelAddress = new JLabel("Address"); labelAccType = new JLabel("Account Type"); labelPhone = new JLabel("Phone"); labelAnnualIncome = new JLabel("AnnualIncome"); textFName = new JTextField(30); textLName = new JTextField(30); textAddress = new JTextField(30); comboAccType = new JComboBox(AccType); textPhone = new JTextField(30); textAnnualIncome = new JTextField(30); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=5; g1.setConstraints(labelFName,gbc); panel.add(labelFName); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=5; g1.setConstraints(textFName,gbc); panel.add(textFName); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=8; g1.setConstraints(labelLName,gbc); panel.add(labelLName); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=8; g1.setConstraints(textLName,gbc); panel.add(textLName); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=11; g1.setConstraints(labelAddress,gbc); panel.add(labelAddress); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=11; g1.setConstraints(textAddress,gbc); panel.add(textAddress); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=14; g1.setConstraints(labelAccType,gbc); panel.add(labelAccType); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=14; g1.setConstraints(comboAccType,gbc); panel.add(comboAccType); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=17; g1.setConstraints(labelPhone,gbc); panel.add(labelPhone); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=17; g1.setConstraints(textPhone,gbc); panel.add(textPhone); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=1; gbc.gridy=20; g1.setConstraints(labelAnnualIncome,gbc); panel.add(labelAnnualIncome); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=20; g1.setConstraints(textAnnualIncome,gbc); panel.add(textAnnualIncome); gbc.anchor=GridBagConstraints.NORTHWEST; gbc.gridx=4; gbc.gridy=23; g1.setConstraints(Store,gbc); panel.add(Store); Store.addActionListener(this); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source == Store) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con; con=DriverManager.getConnection("jdbc:odbc:ebank","sa",""); PreparedStatement stat2; stat2=con.prepareStatement("insert into Registration(cFirst_name,cLast_name,cAdress,cAccount_type,cPhone_no,mAnnual_income) values(?,?,?,?,?,?)"); stat2.setString(1,textFName.getText()); stat2.setString(2,textLName.getText()); stat2.setString(3,textAddress.getText()); stat2.setString(4,(String)comboAccType.getSelectedItem()); stat2.setString(5,textPhone.getText()); stat2.setFloat(6,Float.parseFloat(textAnnualIncome.getText())); stat2.executeUpdate(); JOptionPane.showMessageDialog(frame,new String("Your Details hav been updated")); } catch (Exception exception) { JOptionPane.showMessageDialog(frame,new String("error while entering in database"+exception)); } } }} |