Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. @SuppressWarnings("unused")
  5. public class sql_login {
  6. public static void main(String[] args) {
  7. int id = 0;
  8. Connection con = null;
  9. Statement st = null;
  10. ResultSet rs = null;
  11. Scanner input = new Scanner(System.in);
  12. String e_mail;
  13. String username;
  14. String password;
  15. System.out.println("Welcome. To access the calculator, please authenticate yourself:");
  16. System.out.println("Enter E-mail:");
  17. e_mail = input.next();
  18. System.out.println("Enter UserName:");
  19. username = input.next();
  20. System.out.println("Enter Password:");
  21. password = input.next();
  22. try {
  23. Class.forName("oracle.jdbc.driver.OracleDriver");
  24. // Case Sensitive, Driver LOading
  25. con = DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:XE", "tushar", "yahoo123");
  26. st = con.createStatement();
  27. rs = st.executeQuery("select id from userdatabase where e_mail='" + e_mail + "'" + "and username='"
  28. + username + "'" + "and password='" + password + "'");
  29. while (rs.next()) {
  30. String ids = rs.getString("id");
  31. id = Integer.parseInt(ids);
  32. }
  33. st.close();
  34. con.close();
  35. } catch (Exception e) {
  36. System.out.println(e.getMessage());
  37.  
  38. }
  39. if (id == 0) {
  40. System.out.println("Wrong Username or password");
  41. } else {
  42. System.out.println("Authorised");
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement