diff --git a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java index aee2d8fe593cc..070a84e785631 100644 --- a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java +++ b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.infra.hint.HintValueContext; @@ -90,6 +91,8 @@ private Collection getCurrentDatabaseNames(final ConnectionContext conne * @return used database */ public ShardingSphereDatabase getUsedDatabase() { + ShardingSpherePreconditions.checkNotNull(usedDatabaseNames, NoDatabaseSelectedException::new); + ShardingSpherePreconditions.checkNotEmpty(usedDatabaseNames, NoDatabaseSelectedException::new); ShardingSpherePreconditions.checkState(usedDatabaseNames.size() <= 1, () -> new UnsupportedSQLOperationException(String.format("Can not support multiple logic databases [%s]", Joiner.on(", ").join(usedDatabaseNames)))); String databaseName = usedDatabaseNames.iterator().next();