Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nkotb;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Scanner;
- public class Login {
- Scanner userInput = new Scanner(System.in);
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- public void Login() {
- System.out.println("Name:");
- String loginUsername = userInput.next();
- System.out.println("Password:");
- String loginPassword = userInput.next();
- try {
- Connect conObj = new Connect();
- conObj.Connection();
- //2. Skapa ett statement med scannervaribaler.
- stmt = conn.prepareStatement("SELECT * FROM customers WHERE Name ='" + loginUsername + "' AND Password='" + loginPassword + "' ; ");
- //3. Kör sql-query
- rs = stmt.executeQuery();
- while (rs.next()) {
- String dbName = rs.getString("Name");
- String dbSurname = rs.getString("Surname");
- System.out.println("Welcome " + dbName + " " + dbSurname + "");
- }
- } catch (SQLException exc) {
- System.out.println(exc.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement