public boolean isValidUser() throws SQLException { CreateJDBCConnection jdbc = new CreateJDBCConnection(); Statement stmt = jdbc.getStatement(); stmt.execute("use jana;"); String sqlQuery = "select password from user_details where idno = '" + nameText.getText() + "';"; ResultSet rs = stmt.executeQuery(sqlQuery); while (rs.next()) { if (rs.getString("password").equals(passText.getText())) return true; } return false; }
public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { if (makeConnection()) { if (!t1.getText().equals("") & !t2.getText().equals("") & !t3.getText().equals("") & !t4.getText().equals("")) { det dez = new det(); if (dez.date(t4.getText())) { String a = t1.getText(); String b = t2.getText(); String c = t3.getText(); String d = t4.getText(); String ef = t5.getText(); try { st = cn.createStatement(); String sql = "insert into detalle_ventas values('"; sql += a; sql += "', '"; sql += b + "', '" + c + "', '" + d + "', '" + ef; sql += "')"; int eaz = st.executeUpdate(sql); javax.swing.JOptionPane.showMessageDialog( null, "Se han creado " + eaz + " registros en la base de datos", "informacion", javax.swing.JOptionPane.INFORMATION_MESSAGE); start(); } catch (SQLException exz) { javax.swing.JOptionPane.showMessageDialog( null, "Ha ocurrido un error, favor de checar que la clave no ha sido ingresada ya con anterioridad \n si el problema persiste contacte con el administrador \nError: " + exz.getSQLState() + "" + exz.getMessage(), "Error", javax.swing.JOptionPane.INFORMATION_MESSAGE); } catch (Exception ez) { System.out.println(ez.getMessage()); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar la fecha con un formato correcto dd/mm/aaaa", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar todos los datos correctamente", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Un error ha ocurrido al intentar conectar con la base de datos, \n reinicie el componente o contacte con el administrador", "Error", javax.swing.JOptionPane.ERROR_MESSAGE); } } try { cn.close(); } catch (Exception esa) { System.out.println(esa.getMessage()); } }
public void actionPerformed(ActionEvent ae) { String s1 = ae.getActionCommand(); if (s1.equals("Calendar")) { // DatePicker dp=new DatePicker(f); // dp.displayDate(); // f.getContentPane().add(p); b3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { t6.setText(new DatePicker(f).setPickedDate()); } }); } else if (s1.equals("LogOut")) { f.dispose(); start p = new start(); p.method(); } else if (s1.equals("Search")) { try { String data = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery("select * from mprofile where Manager_Id='" + data + "' "); while (rs.next()) { String a2 = rs.getString(1); t2.setText(a2); String a3 = rs.getString(2); t3.setText(a3); String a4 = rs.getString(3); t4.setText(a4); String a5 = rs.getString(4); t5.setText(a5); String a6 = rs.getString(6); t6.setText(a6); String a7 = rs.getString(7); t7.setText(a7); String a8 = rs.getString(8); t8.setText(a8); String a9 = rs.getString(9); t9.setText(a9); String a10 = rs.getString(10); t10.setText(a10); p.add(l3); p.add(t2); p.add(l4); p.add(t3); p.add(l5); p.add(t4); p.add(l6); p.add(t5); p.add(l7); p.add(c1); p.add(c2); p.add(l8); p.add(t6); p.add(l9); p.add(t7); p.add(l10); p.add(t8); p.add(l11); p.add(t9); p.add(l12); p.add(t10); p.add(b2); p.add(b3); p.add(b4); } } catch (Exception e) { } } else if (s1.equals("Update")) { String y2 = t2.getText(); String y3 = t3.getText(); String update_id = t4.getText(); String y4 = t5.getText(); String y6 = t6.getText(); String y7 = t7.getText(); String y8 = t8.getText(); String y9 = t9.getText(); String y10 = t10.getText(); try { String y = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); PreparedStatement ps = con.prepareStatement( "update mprofile set Location=? , E_Mail_Id=? ,Contact_No =?, Address=?, D_O_B=?,Gender=?, Password=?, Manager_Id=?,manager_father=?,manager_name=? where Manager_Id='" + y + "' "); ps.setString(1, y10); ps.setString(2, y9); ps.setString(3, y8); ps.setString(4, y7); ps.setString(5, y6); ps.setString(6, g); ps.setString(7, y4); ps.setString(8, update_id); ps.setString(9, y3); ps.setString(10, y2); ps.executeUpdate(); JOptionPane.showMessageDialog(p, "data has been updated"); f.dispose(); project p = new project(); p.method(); } catch (Exception e) { System.out.println(e); } } else if (s1.equals("Close")) { f.dispose(); } else { f.dispose(); project p = new project(); p.method(); } }