Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Scanner;
- @SuppressWarnings("unused")
- public class sql_login {
- public static void main(String[] args) {
- int id = 0;
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- Scanner input = new Scanner(System.in);
- String e_mail;
- String username;
- String password;
- System.out.println("Welcome. To access the calculator, please authenticate yourself:");
- System.out.println("Enter E-mail:");
- e_mail = input.next();
- System.out.println("Enter UserName:");
- username = input.next();
- System.out.println("Enter Password:");
- password = input.next();
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- // Case Sensitive, Driver LOading
- con = DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:XE", "tushar", "yahoo123");
- st = con.createStatement();
- rs = st.executeQuery("select id from userdatabase where e_mail='" + e_mail + "'" + "and username='"
- + username + "'" + "and password='" + password + "'");
- while (rs.next()) {
- String ids = rs.getString("id");
- id = Integer.parseInt(ids);
- }
- st.close();
- con.close();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- if (id == 0) {
- System.out.println("Wrong Username or password");
- } else {
- System.out.println("Authorised");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement