|
|
|
Got a question for us?
Just Ask!
$15 Gift Certificate for every bug you find.
|
Topic: ResultSet- writing nulls as ""
Back to Topics
|
|
Posts RSS Feed
|
| |
I am saving a JDBC resultset to fiile.
Could anyone advise me how I can make all values that are null as "" i.e. as a blank.
Thanks in advance
Q
|
|
Q Khawaja
|
Aug 01 2005 14:51
|
CsvManager saves a ResultSet to a file using the ResultSetLineProvider class. The reason that nulls are not blank is from this line:
field = String.valueOf( iResultSet.getObject( iFieldIndex ) );
in the nextFieldImpl method.
(the source of ResultSetLineProvider is shown in the API documentation).
To change the behaviour of this class, you need create your own ResultSetLineProvider that does what you need - so subclass ResultSetLineProvider, and then say:
csvManager.getCsvManagerStore().setResultSetLineProvider( myResultSetLineProvider );
In your own Provider, use something like:
String field = "";
Object obj = iResultSet.getObject( iFieldIndex );
if( null == obj ) {
field = "";
}
else {
field = String.valueOf(obj);
}
In the next version of CsvManager, I will make this more configurable, so thanks for pointing it out.
|
|
Richard Rodger [Ricebridge Staff]
|
Aug 01 2005 15:55
|
|
Unfortunately iResultSet and iFieldIndex are private in the super class and are therefore not visible to the subclass
|
|
Q Khawaja
|
Aug 02 2005 11:56
|
Ouch! Good Point - that will have to change.
As a workaround to solve your problem, I would suggest making a full copy of ResultSetLineListener and modifying that, instead of subclassing.
|
|
Richard Rodger [Ricebridge Staff]
|
Aug 02 2005 11:59
|
|
where can I get the source for this class?
|
|
Q Khawaja
|
Aug 02 2005 12:07
|
|
scratch that I have got it, thanks
|
|
Q Khawaja
|
Aug 02 2005 12:10
|
In order for the CsvManagerStore.setResultSetLineProvider method to work, you will still need to subclass the original ResultSetLineProvider. Of course, your own class will have the full implementation and not actually use anything from the super-class.
|
|
Richard Rodger [Ricebridge Staff]
|
Aug 02 2005 14:41
|
| |
50 Per Page
(total: 7)
|
|
| |
|