Here you can find the source of getSQLException(String message, String sqlState, Exception exception)
public static SQLException getSQLException(String message, String sqlState, Exception exception)
//package com.java2s; import java.lang.reflect.Method; import java.sql.*; public class Main { /**/*from w ww . j a v a2 s. c o m*/ * Returns a SQLException and sets the initCause if running with a 1.4+ JVM. */ public static SQLException getSQLException(String message, String sqlState, Exception exception) { return getSQLException(message, sqlState, Integer.MIN_VALUE, exception); } /** * Returns a SQLException and sets the initCause if running with a 1.4+ JVM. */ public static SQLException getSQLException(String message, String sqlState, int vendorCode, Exception exception) { SQLException sqlException; if (exception != null) { if (message == null) { message = exception.getMessage(); } else { message += ": " + exception.getMessage(); } } if (vendorCode == Integer.MIN_VALUE) { sqlException = new SQLException(message, sqlState); } else { sqlException = new SQLException(message, sqlState, vendorCode); } if (exception != null) { Class sqlExceptionClass = sqlException.getClass(); Class[] parameterTypes = new Class[] { Throwable.class }; Object[] arguments = new Object[] { exception }; try { Method initCauseMethod = sqlExceptionClass.getMethod( "initCause", parameterTypes); initCauseMethod.invoke(sqlException, arguments); } catch (NoSuchMethodException e) { // Ignore; this method does not exist in older JVM's. } catch (Exception e) { // Ignore all other exceptions, do not prevent the main exception // from being returned if reflection fails for any reason... } } return sqlException; } }