fini ex 1 du transition
This commit is contained in:
BIN
DEV3.1/base_donne/Vote.class
Normal file
BIN
DEV3.1/base_donne/Vote.class
Normal file
Binary file not shown.
47
DEV3.1/base_donne/Vote.java
Normal file
47
DEV3.1/base_donne/Vote.java
Normal file
@@ -0,0 +1,47 @@
|
||||
import java.sql.*;
|
||||
|
||||
public class Vote{
|
||||
|
||||
public static void main (String[] arg){
|
||||
try{
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
}catch(ClassNotFoundException e){
|
||||
System.err.println("pas de disponibilité");
|
||||
System.exit(1);
|
||||
}
|
||||
try{
|
||||
Connection bd = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/felix-vi",
|
||||
"felix-vi", "felix-vi");
|
||||
try{
|
||||
PreparedStatement pst = bd.prepareStatement(
|
||||
"SELECT votants, points FROM Vote WHERE competiteur = ?");
|
||||
pst.setString(1, arg[0]);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
try{
|
||||
int total = 0;
|
||||
while(rs.next()) {
|
||||
total += rs.getInt(2);
|
||||
System.out.print(rs.getString(1));
|
||||
System.out.print(" ");
|
||||
System.out.println(rs.getInt(2));
|
||||
}
|
||||
System.out.print("Total ");
|
||||
System.out.println(total);
|
||||
rs.close();
|
||||
}catch(SQLException e){
|
||||
System.err.println("mal affichage");
|
||||
System.exit(1);
|
||||
}
|
||||
pst.close();
|
||||
}catch(SQLException e){
|
||||
System.err.println("mal execute");
|
||||
System.exit(1);
|
||||
}
|
||||
bd.close();
|
||||
}catch(SQLException e){
|
||||
System.err.println("mauvais mdp");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user