想把这个String类型放到一个数组中然后返回,可是我用了String[] 不行,因为String无法直接放入String[]怎么办

图片说明

根据你的意思理解,就是想返回一个表的有列名,并以数组返回,根据你现有代码,加入了数组。

ResultSet rs = ps.executeQuery();
if (rs != null) {
    int count = rs.getMetaData().getColumnCount();
    String[] colNames = new String[count];  //这个数组用来存放一行的所有字段
    while(rs.next()){
                for(int i = 1; i<=count; i++) {
                        String field = rs.getMetaData().getColumnName(i);
                        colNames[i] = field;
                }
                break;
    }
}

connection.close();
ps.close();
return colNames;