public List<Map> getRecords(String tableName, List<String> columnNames)
    throws SQLException, Exception {
        List<Map> Records = new ArrayList();
        
        Statement stmt = null;
        ResultSet rs = null;
        ResultSetMetaData metaData = null;
        Map record = null;
        
        String sql = "SELECT ";
        for(String col : columnNames){
            sql += col + ",";
        }
        sql = sql.substring(0,sql.length()-1);
        sql += " FROM " + tableName;
        
        String driverClassName = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/restaurant";
        String userName = "root";
        String password = "1337passfort";

        try {
                  Class.forName (driverClassName);
                  conn = DriverManager.getConnection(url, userName, password);
        }
        catch ( ClassNotFoundException cnfex ) {
           System.err.println(
                  "Error: Failed to load JDBC driver!" );
           cnfex.printStackTrace();
           System.exit( 1 );  // terminate program
        }
        catch ( SQLException sqlex ) {
           System.err.println( "Error: Unable to connect to database!" );
           sqlex.printStackTrace();
           System.exit( 1 );  // terminate program
        }
                
                
        try {
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            metaData = rs.getMetaData();
            final int fields=metaData.getColumnCount();

            while( rs.next() ) {
                    record = new HashMap();
                    for( int i=1; i <= fields; i++ ) {
                            try {
                                    record.put( metaData.getColumnName(i), rs.getObject(i) );
                            } catch(NullPointerException npe) { 
                                    // no need to do anything... if it fails, just ignore it and continue
                            }
                    } // end for
                    Records.add(record);
            } // end while

            } catch (SQLException sqle) {
                    throw sqle;
            } catch (Exception e) {
                    throw e;
            } finally {
                    try {
                            stmt.close();
                            conn.close();
                    } catch(SQLException e) {
                            throw e;
                    } // end try
            }
        
        return Records;
    }