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
   |  
 
try{
			Statement stmt = connect().createStatement();
			String query  = "use "+database+";";
			boolean exec = stmt.execute(query);
			if(exec){
				String query2 = "show tables;";
				ResultSet set = stmt.executeQuery(query2);
				while(set.next()){
					System.out.println(set.getString(1));
				}
			}
 
		}catch( Exception e ) {
			e.printStackTrace();
		}//end catch
}
 
 
 
	public Connection connect(){
		try
		{
			String userName = "root";
			String password = "";
			String url = "jdbc:mysql://localhost:3306/esial2a";
			Class.forName ("com.mysql.jdbc.Driver").newInstance ();
			conn = DriverManager.getConnection (url, userName, password);
			return conn;
		}
		catch(Exception e){
			System.err.println("Database connection aborted");
			return null;
		}
	} | 
Partager