1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
import java.sql.*;
import java.io.*;
import java.util.Scanner;
class Projetsql{
public static void main(String[] args){
//Nom de mon pilote
//String pilote = "com.mysql.jdbc.Driver";
String pilote = "org.postgresql.Driver";
try{
//Chargement de mon pilote
Class.forName(pilote);
//Class.forName(pilote).newInstance();
//Connexion à ma base postgresql avec mon login et mot de passe
Connection connexion = DriverManager.getConnection("jdbc:postgresql://localhost:5432/gestionhot","postgres","postgres");
//Création de mon statement qui va me permettre d'executer mes requetes
Statement instruction = connexion.createStatement();
Scanner sc = new Scanner(System.in);
int reponse;
String login, motdepasse;
System.out.println("---------------------------");
System.out.println("1 pour client");
System.out.println("2 pour agent");
System.out.println("3 pour administrateur");
System.out.println("---------------------------");
reponse = sc.nextInt();
if (reponse==1){}
if (reponse==2){}
if (reponse==3){
System.out.println("login:");
login=sc.next();
System.out.println("mot de passe:");
motdepasse=sc.next();
ResultSet resultat = instruction.executeQuery("SELECT * FROM Administrateur WHERE loginad="+login+" AND passwordad="+motdepasse);
if (resultat!=null) System.out.println("connecté");
resultat.close();
}
connexion.close();
sc.close();
}
catch (Exception e){System.out.println("echec pilote : "+e);}
}
} |