Changeset 170

Show
Ignore:
Timestamp:
12/04/07 12:39:04 (1 year ago)
Author:
chris
Message:

Improve error checking in SqlDatabase?.getSingleInteger (no longer throws SQLException)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/db/sql/SqlDatabase.java

    r169 r170  
    193193         
    194194    public int getSingleInteger(String query) 
    195     throws DatabaseException, SQLException 
     195    throws DatabaseException 
    196196    { 
    197197        prepareSelect(query); 
    198198         
    199199        ResultSet rs = select(); 
    200         rs.next(); 
    201         int value = rs.getInt(1); 
     200         
     201        try 
     202        { 
     203                if (!rs.next()) 
     204                { 
     205                        throw new DatabaseException("No results", query); 
     206                } 
     207        } 
     208        catch (SQLException e) 
     209        { 
     210                throw new DatabaseException("No results", e); 
     211        } 
     212         
     213        int value; 
     214         
     215        try 
     216        { 
     217                value = rs.getInt(1); 
     218        } 
     219        catch (SQLException e) 
     220        { 
     221                throw new DatabaseException("Failed to get value of " + 
     222                                "column 1 as integer", e); 
     223        } 
     224         
    202225        finish(); 
    203226