printwriter - Hiding headers from a query in java program -
so have program spits out data google csv file. want allow users choose display headers or not via using string.
here printer:
...some code // getting queries print if (results.getrows() == null || results.getrows().isempty()) { pw.println("no results found."); system.out.println("no results found."); } else { // print column headers. (columnheaders header : results.getcolumnheaders()) { pw.print(header.getname() + ", "); } pw.println(); // print actual data. (list<string> row : results.getrows()) { (string column : row) { pw.print(column + ","); } pw.println(); } pw.close(); } } }
i have properties file connected program , want put when user types in no in header part of properties file dont want headers show.
i thinking converting header part string , putting in if statement. suggestions? thx in advanced
edit:
// column headers statement if (headers=="yes") { (columnheaders header : results.getcolumnheaders()) pw.print(header.getname() + ", "); } else { // print column headers. (columnheaders header : results.getcolumnheaders()) { pw.print("" + ", "); } pw.println(); } // getting queries print if (results.getrows() == null || results.getrows().isempty()) { pw.println("no results found."); system.out.println("no results found."); } else { // print actual data. (list<string> row : results.getrows()) { (string column : row) { pw.print(column + ","); } pw.println(); } pw.close(); } } }
but have not working correctly.
first thing first, not checking user input correctly match
you need change
if (headers=="yes") {
to
if (headers.equals("yes")) {
i rid of else statement printing out nothing in first row except commas. want first row commas?
make sure close stream @ end no matter what, too. looks pw.close() in else statement.
Comments
Post a Comment