BUT2/DEV/DEV3.1/TP03_MisesEnPage/Q2GetBD.java

54 lines
1.5 KiB
Java
Raw Normal View History

2023-10-12 16:39:49 +02:00
import org.mariadb.jdbc.*;
import java.sql.*;
public class Q2GetBD{
public static String[] getBD() {
try{
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/wamster",
"wamster","32201909");
try {
Class.forName("org.mariadb.jdbc.Driver");
}
catch(ClassNotFoundException e){
cnx.close();
return null;
}
try {
Q2Array<String> resultat = new Q2Array();
PreparedStatement pstChamp = cnx.prepareStatement(
"SELECT * FROM DEV31TP02Q2_Champ");
ResultSet rsChamp = pstChamp.executeQuery();
while (rsChamp.next()){
int idChamp = rsChamp.getInt("id");
String nomChamp = rsChamp.getString("c0de");
Q2Array<String[]> listeModule = new Q2Array();
listeModule.add(nomChamp);
PreparedStatement pstModule = cnx.prepareStatement(
"SELECT score FROM DEV31TP02Q2_Module WHERE id=?");
pstModule.setInt(1, idChamp);
ResultSet rsModule = pstModule.executeQuery();
pstModule.close();
while (rsModule.next()){
listeModule.add(rsModule.getInt("score"));
}
rsModule.close();
resultat.add(listeModule.getListe());
}
rsChamp.close();
pstChamp.close();
cnx.close();
return new resultat.getListe();
}
catch(SQLException e){
cnx.close();
return null;
}
}
catch(SQLException e){
return null;
}
}
}