Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package ems;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. import java.sql.*;
  11. public class MyMethods {
  12.  
  13. public int login(String userText, String passText) {
  14. int loginVerification = 0;
  15. String pasvord = "dummy";
  16. try {
  17.  
  18. Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/nova_sema", "asmir", "sifra");
  19.  
  20. Statement myStmt = myConn.createStatement();
  21.  
  22. ResultSet result = myStmt.executeQuery("SELECT id, username, password FROM Users WHERE username='"+userText+"' AND password='"+passText+"'");
  23. if (result.next() == false) {
  24. JOptionPane.showMessageDialog(null, "Pogresni Podaci");
  25. }
  26.  
  27. int id = result.getInt("id");
  28. String username = result.getString("username");
  29. String password = result.getString("password");
  30.  
  31. //Provjera
  32. if (id == 1) {
  33. JOptionPane.showMessageDialog(null, "admin");
  34. }else{
  35. JOptionPane.showMessageDialog(null, "not admin");
  36. }
  37.  
  38.  
  39.  
  40.  
  41. }
  42. catch (Exception exc){
  43. exc.printStackTrace();
  44. }
  45. return loginVerification;
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement