Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public class Login {
  2.  
  3. Connection con;
  4. Statement st;
  5. ResultSet rs;
  6.  
  7. JFrame f = new JFrame("User Login");
  8. JLabel l = new JLabel("Username");
  9. JLabel l1 = new JLabel("Password");
  10. JTextField t = new JTextField(10);
  11. JTextField t1 = new JTextField(10);
  12. JButton b = new JButton("Login");
  13.  
  14. public Login {
  15. connect();
  16. frame();
  17.  
  18. }
  19.  
  20. public void connect {
  21.  
  22. try {
  23.  
  24. String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  25. Class.forName(driver);
  26.  
  27. String db = "jdbc:odbc:DATENBANKNAME";
  28. con = DriverManager.getConnection(db);
  29. st = con.createStatement();
  30.  
  31. }
  32.  
  33. catch(Exception ex) {
  34.  
  35.  
  36. }
  37. }
  38.  
  39. public void frame() {
  40. f.setSize(600,400);
  41. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42. f.setVisible(true);
  43.  
  44. JPanel p = new JPanel();
  45. p.add(l);
  46. p.add(t):
  47. p.add(l1);
  48. p.add(t1);
  49. p.add(b);
  50.  
  51. f.add(p);
  52.  
  53. b.addActionListener(new ActionListener() {
  54. public void actionPerformed(ActionEvent e) {
  55.  
  56. try {
  57. String user = t.getText().trim();
  58. String pass = t1.getTExt().trim();
  59.  
  60. String sql = "select user,pass from TABLENAME where user = '" +user+"'and pass = '"+pass+"'";
  61. rs = st.executiveQuery(sql);
  62.  
  63. int count = 0;
  64. while(rs.next()) {
  65. count = count + 1;
  66. }
  67.  
  68. if(count == 1) {
  69. JOptionPane.showMessageDialog(null, "User wurde gefunden";
  70. }
  71.  
  72. else if(count > 1) {
  73. JOptionPane.showMessageDialog(null, "User ist mehrmals vorhanden!");
  74. }
  75.  
  76. else {
  77. JOptionPane.showMessageDialog(null, "User wurde nicht gefunden!);
  78. }
  79.  
  80. }
  81. catch(Exception ex) {
  82.  
  83. }
  84.  
  85. }
  86. });
  87.  
  88. }
  89.  
  90.  
  91.  
  92. public static void main(String[] args) {
  93. new Login();
  94. }
  95.  
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement