Search This Site
Sep 02 2010 23:10 UTC | ||||||||||
Tutorials
CSV ManagerRatingsQuality
Recommendations
Questions
Got a question for us? Bookmarks |
ResultSet Data
CSV Manager can load and save your data as a JDBC Code Example
File csvfile = new File("mydata.csv");
CsvManager csvman = new CsvManager();
csvman.getCsvSpec().setProperty( "ResultSet.dataHasHeaders", true );
ResultSet rs = csvman.loadResultSet( csvfile );
ResultSetMetaData md = rs.getMetaData();
int numCols = md.getColumnCount();
for( int col = 1; col <= numCols; col++ ) {
System.out.print( md.getColumnName(col) + (col<numCols?", ":"\n") );
}
while( rs.next() ) {
for( int col = 1; col <= numCols; col++ ) {
System.out.print( rs.getString(col) + (col<numCols?", ":"\n") );
}
}
This code example loads the data in a CSV file into an object which implements the Use this method when...
loadResultSet method can take a String
containing the file path, or a File object. It also takes
an additional boolean parameter telling it whether to expect column
headers at the top of the CSV file or not.
What happens when some rows contain more fields than others?
You can only access extra fields if you know they are there. CSV
Manager returns the number of data fields found in the first row
via the What happens when some rows are missing fields?
CSV Manager keeps track of the default number of data fields
that you expect in your CSV file (you can set the
default number of fields,
or let CSV Manager automatically use the
number of fields in the first row). When fields are missing,
the OK, how do I get the column headers?
CSV Manager also implements the ResultSetMetaData interface.
Assuming the headers are in the first line of the CSV file, you can access them
via the standard methods of But my data isn't in a file!
You are not restricted to loading CSV data only from files. You can also load data from
What about saving data to a CSV file?
You can also save data to a CSV file using a
File csvfile = new File("mydata.csv");
CsvManager csvman = new CsvManager();
Connection con = getDatabaseConnection(); // return a java.sql.Connection
// assume a Product table in database
PreparedStatement ps
= con.prepareStatement( "SELECT * FROM Product" );
ResultSet rs = ps.executeQuery();
csvman.saveResultSet( csvfile, rs );
CSV Manager can use the ResultSetMetaData object from the database ResultSet to output column headers. See the save method description for more details. What other data structures can you handle?We also support: I need to see something working.Sure, no problem. Head on over to our online demo and try out CSV Manager on your own data. I have another question...If you have a particular question you need answered, just ask! We're happy to explain exactly how CSV Manager works and show you how to use it. |
FREE Email SupportAll CSV Manager licenses include a FREE 6 month Email Support Package, worth $1500.00. FREE XML ManagerAll CSV Manager licenses include a FREE XML Manager single developer license, worth $170.00. Any CSV FormatThe CSV Manager component can handle any style of tabular text data, from Excel CSV files to the UNIX passwd file.
| ||||||||
|
comment on this page
Home |
Search |
About Us |
Contact Us |
Our Products |
Documentation |
Resources |
Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved. | ||||||||||