How to create a PreparedStatement/ResultSet with a blank record?
821960Dec 7 2010 — edited Dec 9 2010I want to query my database and if no records are found I want to have a valid result set filled with blanks (or zeros) for the proper columns.
For example, given this code:
<pre>
PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM address WHERE name = ?",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
statement.setString(1,myAddress);
ResultSet rs = statement.executeQuery();
while (rs.next())
{
System.out.println("Zip Code: '" + rs.getString("zip") + "'");
}
</pre>
If a record is found, the output would be
<pre>
Zip Code: '12345'
</pre>
If no record is found the output would be
<pre>
Zip Code: ''
</pre>
Can that be done easily by tinkering with the PreparedStatement or ResultSet?
My fallback is to create a class that maps to the database and have the constructor handle the processing.