private void display() { if (!String.valueOf(viewtype.getSelectedItem()).equalsIgnoreCase("ATM PIN")) { if (jLabel5.isEnabled()) { jLabel5.setEnabled(false); jTextField1.setEnabled(false); } } String str; Object row[] = new Object[5]; DefaultTableModel dm = (DefaultTableModel) display.getModel(); while (dm.getRowCount() > 0) dm.removeRow(0); if (viewtype.getSelectedIndex() == 0) { str = "select * from " + Login.user + ";"; } /* new changes made as per the new requirements*/ else if (String.valueOf(viewtype.getSelectedItem()).equalsIgnoreCase("ATM PIN")) { jTextField1.setEnabled(true); jLabel5.setEnabled(true); if (jTextField1.getText().trim().equals("")) str = "select * from " + Login.user + " where type='" + String.valueOf(viewtype.getSelectedItem()) + "';"; else str = "select * from " + Login.user + " where type='" + String.valueOf(viewtype.getSelectedItem()) + "' AND accountname ='" + jTextField1.getText().trim() + "';"; } else { str = "select * from " + Login.user + " where type='" + String.valueOf(viewtype.getSelectedItem()) + "';"; } try { ResultSet rs = PasswordManager.st.executeQuery(str); while (rs.next()) { for (int i = 0; i < 5; i++) { if (i != 2) row[i] = rs.getString(i + 1); else row[i] = PasswordManager.decrypt(String.valueOf(rs.getString(3))); } dm.addRow(row); } display.setModel(dm); } catch (SQLException se) { JOptionPane.showMessageDialog(this, "Database Error", "Error", JOptionPane.ERROR_MESSAGE); } }
/** Creates new form Home */ public Home() { initComponents(); try { PasswordManager.connect(); String str = "select name from details where username='******';"; ResultSet rs = PasswordManager.st.executeQuery(str); rs.next(); jLabel1.setText("Welcome , " + rs.getString("name")); } catch (SQLException se) { System.out.println("Connection to Database failed ..."); } jLabel5.setEnabled(false); jTextField1.setEnabled(false); }
private void jButton2ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed if (name.getText().equals("") || pass.getText().equals("")) { JOptionPane.showMessageDialog( this, "Account Name & Password cannot be left blank", "Error", JOptionPane.ERROR_MESSAGE); } else { Calendar cl = Calendar.getInstance(); Date cr = Date.valueOf( cl.get(Calendar.YEAR) + "-" + (cl.get(Calendar.MONTH) + 1) + "-" + cl.get(Calendar.DAY_OF_MONTH)); String str = "insert into " + Login.user + "(`accountname`,`password`,`type`,`created`) values('" + name.getText() + "','" + PasswordManager.encrypt(pass.getText()) + "','" + String.valueOf(type.getSelectedItem()) + "','" + cr + "');"; try { PasswordManager.st.executeUpdate(str); JOptionPane.showMessageDialog( this, "Password saved successfully ...", "Success", JOptionPane.INFORMATION_MESSAGE); reset(); } catch (SQLException se) { JOptionPane.showMessageDialog( this, "Failed to write to database", "Error", JOptionPane.ERROR_MESSAGE); } } } // GEN-LAST:event_jButton2ActionPerformed