How to get the number of columns from a JDBC ResultSet?

前端 未结 5 959
旧巷少年郎
旧巷少年郎 2020-12-01 04:07

I am using CsvJdbc (it is a JDBC-driver for csv-files) to access a csv-file. I don\'t know how many columns the csv-file contains. How can I get the number of columns? Is th

5条回答
  •  遥遥无期
    2020-12-01 04:46

    This will print the data in columns and comes to new line once last column is reached.

    ResultSetMetaData resultSetMetaData = res.getMetaData();
    int columnCount = resultSetMetaData.getColumnCount();
    for(int i =1; i<=columnCount; i++){
                    if(!(i==columnCount)){
    
                        System.out.print(res.getString(i)+"\t");
                    }
                    else{
                        System.out.println(res.getString(i));
                    }
    
                }
    

提交回复
热议问题