@@ -84,6 +84,8 @@ final class PooledConnection extends ConnectionDelegator {
8484 private boolean resetAutoCommit ;
8585 private boolean resetSchema ;
8686 private boolean resetCatalog ;
87+ private boolean initialisedSchema ;
88+ private boolean initialisedCatalog ;
8789 private String currentSchema ;
8890 private String currentCatalog ;
8991 private String originalSchema ;
@@ -120,6 +122,8 @@ final class PooledConnection extends ConnectionDelegator {
120122 this .name = pool .name () + uniqueId ;
121123 this .originalSchema = pool .schema ();
122124 this .originalCatalog = pool .catalog ();
125+ this .initialisedSchema = originalSchema != null ;
126+ this .initialisedCatalog = originalCatalog != null ;
123127 this .pstmtCache = new PstmtCache (pool .pstmtCacheSize ());
124128 this .maxStackTrace = pool .maxStackTraceSize ();
125129 this .creationTime = System .currentTimeMillis ();
@@ -700,9 +704,10 @@ public void setSchema(String schema) throws SQLException {
700704 if (status == STATUS_IDLE ) {
701705 throw new SQLException (IDLE_CONNECTION_ACCESSED_ERROR + "setSchema()" );
702706 }
703- if (originalSchema == null ) {
707+ if (! initialisedSchema ) {
704708 // lazily initialise the originalSchema
705709 originalSchema = getSchema ();
710+ initialisedSchema = true ;
706711 }
707712 currentSchema = schema ;
708713 resetSchema = true ;
@@ -714,9 +719,9 @@ public void setCatalog(String catalog) throws SQLException {
714719 if (status == STATUS_IDLE ) {
715720 throw new SQLException (IDLE_CONNECTION_ACCESSED_ERROR + "setCatalog()" );
716721 }
717- if (originalCatalog == null ) {
718- // lazily initialise the originalCatalog
722+ if (!initialisedCatalog ) {
719723 originalCatalog = getCatalog ();
724+ initialisedCatalog = true ;
720725 }
721726 currentCatalog = catalog ;
722727 resetCatalog = true ;
0 commit comments