From 23c16c35e745e5b7b0636de7e7ff9401d44b5ee0 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Wed, 29 Mar 2023 09:17:01 +0700 Subject: [PATCH] bug: Fixed the resultset load alias column and replace to getColumnLabel instead of getColumnName (original name) --- src/main/java/com/cubetiqs/sql/ResultSetUtil.java | 6 +++++- src/test/java/com/cubetiqs/sql/ConnectionTests.java | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cubetiqs/sql/ResultSetUtil.java b/src/main/java/com/cubetiqs/sql/ResultSetUtil.java index ffcaaac..e5f0561 100644 --- a/src/main/java/com/cubetiqs/sql/ResultSetUtil.java +++ b/src/main/java/com/cubetiqs/sql/ResultSetUtil.java @@ -34,7 +34,11 @@ public final class ResultSetUtil { IntStream.range(0, columnCount).forEach(i -> { try { - columns.add(metaData.getColumnName(i + 1)); + String str = metaData.getColumnLabel(i + 1); + if (str == null || str.isEmpty()) { + str = metaData.getColumnName(i + 1); + } + columns.add(str); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/test/java/com/cubetiqs/sql/ConnectionTests.java b/src/test/java/com/cubetiqs/sql/ConnectionTests.java index acc2b4f..38f92fa 100644 --- a/src/test/java/com/cubetiqs/sql/ConnectionTests.java +++ b/src/test/java/com/cubetiqs/sql/ConnectionTests.java @@ -2,7 +2,6 @@ package com.cubetiqs.sql; import org.junit.jupiter.api.Test; -import java.sql.SQLException; import java.util.List; public class ConnectionTests { @@ -19,7 +18,7 @@ public class ConnectionTests { JdbcDataFactory factory = ConnectionFactory .createDataFactory(builder); - IExecuteResult> result = factory.queryForList("select * from um"); + IExecuteResult> result = factory.queryForList("select Status as gg from um"); System.out.println(result.getData()); factory.tryClose();