Ricebridge
Search This Site
Jul 29 2010 16:56 UTC


$15 Gift Certificate for every bug you find.

MaxMind GeoIP
This IP address to country database is provided as a CSV file that can easily be read by CSV Manager.

Got a question for us?
Just Ask!

Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at del.icio.us Digg ResultSet features description for Ricebridge Java CSV Manager Component at Digg.com Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at reddit.com Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at YahooMyWeb Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at Spurl.net Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at Simpy.com Bookmark Polyphasic Mutants at NewsVine Blink this ResultSet features description for Ricebridge Java CSV Manager Component at blinklist.com Bookmark ResultSet features description for Ricebridge Java CSV Manager Component at Furl.net Fark ResultSet features description for Ricebridge Java CSV Manager Component at Fark.com

ResultSet Data

CSV Manager can load and save your data as a JDBC ResultSet.

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 ResultSet interface.

Use this method when...

  • you want all the data in memory.
  • your data has standard columns.
  • you need to pass the CSV data to code that already uses ResultSets.
  • you want to make use of type conversion methods like getInt().
The 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 ResultSetMetaData interface, and assumes that this defines the number of fields in the CSV file. But you can still access extra data fields directly by using field index values that are greater than the default number of fields in the ResultSet get methods. But like a normal ResultSet, if you try to access a data field that does not exist, an exception will be thrown.

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 ResultSet assumes that they are empty strings.

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 ResultSetMetaData such as getColumnCount and getColumnName. If the column names are not in the first line, then they are either in a predefined line (say line 3), so start loading lines from there using setStartLine, or you can set CSV Manager to ignore empty lines, until you find them.

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 Strings (loadFromString(String) method) and from InputStreams (load(InputStream) method). This means that you can use CSV Manager in a completely dynamic way within your application.

What about saving data to a CSV file?

You can also save data to a CSV file using a ResultSet. Connect to your database, run a query, and then hand the ResultSet over to CsvManager to save as a CSV file. Here's the example code:

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 Support

All CSV Manager licenses include a FREE 6 month Email Support Package, worth $1500.00.

Email Support Package

FREE XML Manager

All CSV Manager licenses include a FREE XML Manager single developer license, worth $170.00.

Convert CSV to XML

Any CSV Format

The CSV Manager component can handle any style of tabular text data, from Excel CSV files to the UNIX passwd file.

CSV Formats

"Your product actually did help a lot! I was able to accelerate my development time quite a bit and your service support was also real nice."
Luis Garcia,
Independent Contractor
"An event-based CSV parser is so much more flexible and elegant than the free alternatives that I found. We use it for applications which require a mixture of XML and CSV data. This requires a parser that performs well, uses memory efficiently, simplifies data access and accurately formats output data. We found the Ricebridge parser easy to work with, conspicuously well documented and capable of handling large (500kb+) files. That's a big thumbs up from all the Gaisan team."
Shane Dempsey,
Gaisan
"I would have spent all day trying to read CSV fields that contained commas. I bought your software about 15 minutes ago and my problem is ALREADY solved. Thank you very, very much for a quality piece of software."
Adrian Klingel,
Illumaware
"Ricebridge CSV Manager was really easy to integrate into our existing system, and has been completely reliable for data transfer, not to mention a big time saver!"
Fred Crowe, Speech-Writers
comment on this page Home | Search | About Us | Contact Us | Our Products | Documentation | Resources | Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved.