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
| import java.sql.*;
import java.util.*;
public class ConnectSingleton{
Statement state;
public void afficher(){
try{
ResultSet result = state.executeQuery("SELECT id_etudiant,sexe_etudiant,nom_etudiant FROM etudiant limit 5");
ResultSetMetaData resultMeta = result.getMetaData();
System.out.println("Il y'a " +resultMeta.getColumnCount()+ " Colonnes Dans cette Table");
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
{System.out.println("* " + resultMeta.getColumnName(i));}
System.out.println("\n******************************************************************************");
//On affiche le nom des colonnes
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
{System.out.print("\t" + resultMeta.getColumnName(i).toUpperCase() + "\t *");}
System.out.println("\n*************************************************");
while(result.next()){
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
System.out.print("\t" + result.getObject(i).toString() + "\t |");
System.out.println("\n--------------------------------------------------------------------------"); }
state.close();
result.close();
}catch (Exception e) {
e.printStackTrace();
} }
public static void main(String args[]) {
Singleton.getInstance().afficher();
}
} |
Partager