Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_contact`(IN fnumber int(2))
- BEGIN
- DELETE FROM PHONE_NUMBERS
- WHERE F_number = fnumber;
- DELETE FROM PHYSICAL_ADDRESS
- WHERE F_number = fnumber;
- DELETE FROM EMAIL_ADDRESSES
- WHERE FNumber = fnumber;
- DELETE FROM APPOINTMENTS
- WHERE Fr_No = fnumber;
- DELETE FROM FRIEND
- WHERE F_no = fnumber;
- END
- public class BtnDelete1 extends AbstractAction {
- private FirstSwingApp mainGui;
- public BtnDelete1(FirstSwingApp mainGui) {
- super("Press Me");
- putValue(MNEMONIC_KEY, KeyEvent.VK_P);
- this.mainGui = mainGui;
- }
- public void actionPerformed(ActionEvent e) {
- Object cell = mainGui.getSelectedCell();
- int fnumber = ((int) noText.getText().charAt(0));
- CallableStatement dstmt = null;
- CallableStatement cstmt = null;
- ResultSet rs;
- try {
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Contact_Manager?user=root");
- String SQL = "{call delete_contact (?)}";
- String disQuery = "n" +
- "select FRIEND.F_Name, FRIEND.F_no,FRIEND.Birth_date,FRIEND.Gender,FRIEND.City,FRIEND.State, PHONE_NUMBERS.Extension, PHONE_NUMBERS.Ph_No, PHYSICAL_ADDRESS.Address_Line1, PHYSICAL_ADDRESS.Address_Line2, EMAIL_ADDRESSES.Email_Address, EMAIL_ADDRESSES.Platform, APPOINTMENTS.Notes, APPOINTMENTS.Meeting,APPOINTMENTS.Callsn" +
- "from FRIEND,PHONE_NUMBERS, PHYSICAL_ADDRESS, EMAIL_ADDRESSES, APPOINTMENTSn" +
- "where FRIEND.F_no = PHONE_NUMBERS.F_number = PHYSICAL_ADDRESS.F_number = EMAIL_ADDRESSES.FNumber = APPOINTMENTS.Fr_No;n";
- dstmt = conn.prepareCall(disQuery);
- cstmt = conn.prepareCall(SQL);
- cstmt.setInt(1, fnumber);
- cstmt.executeQuery();
- rs = dstmt.executeQuery();
- ResultSetMetaData metaData = rs.getMetaData();
- // names of columns
- Vector<String> columnNames = new Vector<String>();
- int columnCount = metaData.getColumnCount();
- for (int column = 1; column <= columnCount; column++) {
- columnNames.add(metaData.getColumnName(column));
- }
- // data of the table
- Vector<Vector<Object>> data = new Vector<Vector<Object>>();
- while (rs.next()) {
- Vector<Object> vector = new Vector<Object>();
- for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
- vector.add(rs.getObject(columnIndex));
- }
- data.add(vector);
- }
- // It creates and displays the table
- model.setDataVector(data, columnNames);
- // Closes the Connection
- dstmt.close();
- System.out.println("Success!!");
- } catch (SQLException ex) {
- System.out.println("Error in connection: " + ex.getMessage());
- }
- }
- }
- table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
- @Override
- public void valueChanged(ListSelectionEvent e) {
- int row = table.getSelectedRow();
- System.out.println("Selecte table row = " + row);
- if (row != -1) {
- int modelRow = table.convertRowIndexToModel(row);
- System.out.println("Selecte model row = " + row);
- Vector data = (Vector) ((DefaultTableModel) table.getModel()).getDataVector().get(modelRow);
- nameText.setText(data.get(0).toString());
- noText.setText(data.get(1).toString());
- bdateText.setText(data.get(2).toString());
- sexText.setText(data.get(3).toString());
- cityText.setText(data.get(4).toString());
- stateText.setText(data.get(5).toString());
- extText.setText(data.get(6).toString());
- phoneText.setText(data.get(7).toString());
- add1Text.setText(data.get(8).toString());
- add2Text.setText(data.get(9).toString());
- emailText.setText(data.get(10).toString());
- platText.setText(data.get(11).toString());
- notesText.setText(data.get(12).toString());
- meetText.setText(data.get(13).toString());
- callText.setText(data.get(14).toString());
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement