44import java .io .CharArrayReader ;
55import java .io .InputStream ;
66import java .io .Reader ;
7+ import java .io .StringReader ;
78import java .math .BigDecimal ;
89import java .net .MalformedURLException ;
910import java .net .URL ;
@@ -73,7 +74,7 @@ private String columnIndexToName(int index) throws SQLException {
7374 try {
7475 return getSchema ().columnIndexToName (index );
7576 } catch (Exception e ) {
76- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: columnIndexToName(%s) " , parentStatement .getLastSql (), index ), e );
77+ throw ExceptionUtils .toSqlState (String .format ("Method: columnIndexToName(%s) encountered an exception." , index ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
7778 }
7879 }
7980
@@ -222,7 +223,7 @@ public String getString(String columnLabel) throws SQLException {
222223 return null ;
223224 }
224225 } catch (Exception e ) {
225- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getString(%s) " , parentStatement .getLastSql (), columnLabel ), e );
226+ throw ExceptionUtils .toSqlState (String .format ("Method: getString( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
226227 }
227228 }
228229
@@ -238,7 +239,7 @@ public boolean getBoolean(String columnLabel) throws SQLException {
238239 return false ;
239240 }
240241 } catch (Exception e ) {
241- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getBoolean(%s) " , parentStatement .getLastSql (), columnLabel ), e );
242+ throw ExceptionUtils .toSqlState (String .format ("Method: getBoolean( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
242243 }
243244 }
244245
@@ -254,7 +255,7 @@ public byte getByte(String columnLabel) throws SQLException {
254255 return 0 ;
255256 }
256257 } catch (Exception e ) {
257- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getByte(%s) " , parentStatement .getLastSql (), columnLabel ), e );
258+ throw ExceptionUtils .toSqlState (String .format ("Method: getByte( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
258259 }
259260 }
260261
@@ -270,7 +271,7 @@ public short getShort(String columnLabel) throws SQLException {
270271 return 0 ;
271272 }
272273 } catch (Exception e ) {
273- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getShort(%s) " , parentStatement .getLastSql (), columnLabel ), e );
274+ throw ExceptionUtils .toSqlState (String .format ("Method: getShort( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
274275 }
275276 }
276277
@@ -286,7 +287,7 @@ public int getInt(String columnLabel) throws SQLException {
286287 return 0 ;
287288 }
288289 } catch (Exception e ) {
289- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getInt(%s) " , parentStatement .getLastSql (), columnLabel ), e );
290+ throw ExceptionUtils .toSqlState (String .format ("Method: getInt( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
290291 }
291292 }
292293
@@ -302,7 +303,7 @@ public long getLong(String columnLabel) throws SQLException {
302303 return 0 ;
303304 }
304305 } catch (Exception e ) {
305- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getLong(%s) " , parentStatement .getLastSql (), columnLabel ), e );
306+ throw ExceptionUtils .toSqlState (String .format ("Method: getLong( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
306307 }
307308 }
308309
@@ -318,7 +319,7 @@ public float getFloat(String columnLabel) throws SQLException {
318319 return 0 ;
319320 }
320321 } catch (Exception e ) {
321- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getFloat(%s) " , parentStatement .getLastSql (), columnLabel ), e );
322+ throw ExceptionUtils .toSqlState (String .format ("Method: getFloat( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
322323 }
323324 }
324325
@@ -334,7 +335,7 @@ public double getDouble(String columnLabel) throws SQLException {
334335 return 0 ;
335336 }
336337 } catch (Exception e ) {
337- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getDouble(%s) " , parentStatement .getLastSql (), columnLabel ), e );
338+ throw ExceptionUtils .toSqlState (String .format ("Method: getDouble( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
338339 }
339340 }
340341
@@ -350,7 +351,7 @@ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLExcepti
350351 return null ;
351352 }
352353 } catch (Exception e ) {
353- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getBigDecimal(%s) " , parentStatement .getLastSql (), columnLabel ), e );
354+ throw ExceptionUtils .toSqlState (String .format ("Method: getBigDecimal( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
354355 }
355356 }
356357
@@ -366,7 +367,7 @@ public byte[] getBytes(String columnLabel) throws SQLException {
366367 return null ;
367368 }
368369 } catch (Exception e ) {
369- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getBytes(%s) " , parentStatement .getLastSql (), columnLabel ), e );
370+ throw ExceptionUtils .toSqlState (String .format ("Method: getBytes( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
370371 }
371372 }
372373
@@ -452,7 +453,7 @@ public int findColumn(String columnLabel) throws SQLException {
452453 try {
453454 return reader .getSchema ().getColumnByName (columnLabel ).getColumnIndex ();
454455 } catch (Exception e ) {
455- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: findColumn(%s) " , parentStatement .getLastSql (), columnLabel ), e );
456+ throw ExceptionUtils .toSqlState (String .format ("Method: findColumn( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
456457 }
457458 }
458459
@@ -493,7 +494,7 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
493494 return null ;
494495 }
495496 } catch (Exception e ) {
496- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getBigDecimal(%s) " , parentStatement .getLastSql (), columnLabel ), e );
497+ throw ExceptionUtils .toSqlState (String .format ("Method: getBigDecimal( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
497498 }
498499 }
499500
@@ -1034,7 +1035,7 @@ public java.sql.Array getArray(String columnLabel) throws SQLException {
10341035 column .getArrayBaseColumn ().getDataType ().name (),
10351036 JdbcUtils .convertToSqlType (column .getArrayBaseColumn ().getDataType ()).getVendorTypeNumber ());
10361037 } catch (Exception e ) {
1037- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getArray(%s) " , parentStatement .getLastSql (), columnLabel ), e );
1038+ throw ExceptionUtils .toSqlState (String .format ("Method: getArray( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
10381039 }
10391040 }
10401041
@@ -1046,17 +1047,21 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
10461047 @ Override
10471048 public Date getDate (String columnLabel , Calendar cal ) throws SQLException {
10481049 checkClosed ();
1049- LocalDate d = reader .getLocalDate (columnLabel );
1050- if (d == null ) {
1051- wasNull = true ;
1052- return null ;
1053- }
1054- wasNull = false ;
1050+ try {
1051+ LocalDate d = reader .getLocalDate (columnLabel );
1052+ if (d == null ) {
1053+ wasNull = true ;
1054+ return null ;
1055+ }
1056+ wasNull = false ;
10551057
1056- Calendar c = (Calendar )( cal != null ? cal : defaultCalendar ).clone ();
1057- c .clear ();
1058- c .set (d .getYear (), d .getMonthValue () - 1 , d .getDayOfMonth (), 0 , 0 , 0 );
1059- return new Date (c .getTimeInMillis ());
1058+ Calendar c = (Calendar ) (cal != null ? cal : defaultCalendar ).clone ();
1059+ c .clear ();
1060+ c .set (d .getYear (), d .getMonthValue () - 1 , d .getDayOfMonth (), 0 , 0 , 0 );
1061+ return new Date (c .getTimeInMillis ());
1062+ } catch (Exception e ) {
1063+ throw ExceptionUtils .toSqlState (String .format ("Method: getDate(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
1064+ }
10601065 }
10611066
10621067 @ Override
@@ -1080,7 +1085,7 @@ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
10801085 c .set (1970 , Calendar .JANUARY , 1 , zdt .getHour (), zdt .getMinute (), zdt .getSecond ());
10811086 return new Time (c .getTimeInMillis ());
10821087 } catch (Exception e ) {
1083- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getTime(%s, %s) " , parentStatement .getLastSql (), columnLabel , cal ), e );
1088+ throw ExceptionUtils .toSqlState (String .format ("Method: getTime(\" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
10841089 }
10851090 }
10861091
@@ -1107,7 +1112,7 @@ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLExcept
11071112 timestamp .setNanos (localDateTime .getNano ());
11081113 return timestamp ;
11091114 } catch (Exception e ) {
1110- throw ExceptionUtils .toSqlState (String .format ("SQL: [%s]; Method: getTimestamp(%s) " , parentStatement .getLastSql (), columnLabel ), e );
1115+ throw ExceptionUtils .toSqlState (String .format ("Method: getTimestamp( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s] " , parentStatement .getLastSql ()), e );
11111116 }
11121117
11131118 }
@@ -1122,8 +1127,8 @@ public URL getURL(String columnLabel) throws SQLException {
11221127 checkClosed ();
11231128 try {
11241129 return new URL (reader .getString (columnLabel ));
1125- } catch (MalformedURLException e ) {
1126- throw new SQLDataException ( e . getMessage (), ExceptionUtils . SQL_STATE_DATA_EXCEPTION , e );
1130+ } catch (Exception e ) {
1131+ throw ExceptionUtils . toSqlState ( String . format ( "Method: getURL( \" %s \" ) encountered an exception." , columnLabel ), String . format ( "SQL: [%s]" , parentStatement . getLastSql ()) , e );
11271132 }
11281133 }
11291134
@@ -1291,7 +1296,11 @@ public String getNString(int columnIndex) throws SQLException {
12911296 @ Override
12921297 public String getNString (String columnLabel ) throws SQLException {
12931298 checkClosed ();
1294- return reader .getString (columnLabel );
1299+ try {
1300+ return reader .getString (columnLabel );
1301+ } catch (Exception e ) {
1302+ throw ExceptionUtils .toSqlState (String .format ("Method: getNString(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
1303+ }
12951304 }
12961305
12971306 @ Override
@@ -1302,7 +1311,11 @@ public Reader getNCharacterStream(int columnIndex) throws SQLException {
13021311 @ Override
13031312 public Reader getNCharacterStream (String columnLabel ) throws SQLException {
13041313 checkClosed ();
1305- return new CharArrayReader (reader .getString (columnLabel ).toCharArray ());
1314+ try {
1315+ return new StringReader (reader .getString (columnLabel ));
1316+ } catch (Exception e ) {
1317+ throw ExceptionUtils .toSqlState (String .format ("Method: getNCharacterStream(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
1318+ }
13061319 }
13071320
13081321 @ Override
@@ -1508,7 +1521,8 @@ public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
15081521 return null ;
15091522 }
15101523 } catch (Exception e ) {
1511- throw ExceptionUtils .toSqlState (e );
1524+ throw ExceptionUtils .toSqlState (String .format ("Method: getObject(\" %s\" , %s) encountered an exception." , columnLabel , type ),
1525+ String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
15121526 }
15131527 }
15141528
0 commit comments