I tried to get ResultSet from Vertica
database with Java.
But it returns null
.
SQL query:
SELECT to_char(SUM(my_column)) FROM my_table
UNION ALL SELECT to_char(123) FROM dual
SQL result in DB client:
201198184560.13000
123
Java code:
PreparedStatement ps;
ps = connection.prepareStatement(sqlQuery);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println("Inside loop...");
String str = rs.getString(1);
Float f = rs.getFloat(1);
Double d = rs.getDouble(1);
Object obj = rs.getObject(1);
System.out.println("String: " + str + ", float: " + f + ", double: " + d + ", obj: " + obj);
}
Result in java console:
Inside loop...
String: null, float: 0.0, double: 0.0, obj: null
Inside loop...
String: 123, float: 123.0, double: 123.0, obj: 123
What am I doing wrong? Why Result Set returns null? How can I print all my Result Sets in java console?
Update1: Debug before while rs.next():
rs = {S4ForwardResultSet@1015}
m_logger = {DSILogger@1028}
m_resultMetaData = {S4ResultSetMetaData@1045}
m_currentRow = 0
m_currentStream = null
m_isOpen = true
m_resultSet = {VResultSet@1046}
m_resultSetColumns = {ArrayList@1038} size = 1
m_warningListener = {SWarningListener@1047}
m_wasLastValueNull = false
m_cachedDataWrappers = {ArrayList@1048} size = 1
m_cursorPosition = {CursorPosition@1049} "BEFORE_FIRST"
m_columnNameIndexes = {ArrayList@1050} size = 1
m_numColumns = 1
m_parentStatement = {VerticaJdbc4PreparedStatementImpl@996}
m_jdbcVersion = {JDBCVersion@1030} "JDBC4"
m_streamBufferSize = 32000
Update2: Debug while rs.next() first time:
rs = {S4ForwardResultSet@1013}
m_logger = {DSILogger@1014}
m_resultMetaData = {S4ResultSetMetaData@1015}
m_currentRow = 1
m_currentStream = null
m_isOpen = true
m_resultSet = {VResultSet@1016}
m_resultSetColumns = {ArrayList@1017} size = 1
m_warningListener = {SWarningListener@1018}
m_wasLastValueNull = true
m_cachedDataWrappers = {ArrayList@1019} size = 1
m_cursorPosition = {CursorPosition@1078} "AT_FIRST"
m_columnNameIndexes = {ArrayList@1021} size = 1
m_numColumns = 1
m_parentStatement = {VerticaJdbc4PreparedStatementImpl@996}
m_jdbcVersion = {JDBCVersion@1022} "JDBC4"
m_streamBufferSize = 32000
Debug while rs.next() second time:
m_logger = {DSILogger@1014}
m_resultMetaData = {S4ResultSetMetaData@1015}
m_currentRow = 2
m_currentStream = null
m_isOpen = true
m_resultSet = {VResultSet@1016}
m_resultSetColumns = {ArrayList@1017} size = 1
m_warningListener = {SWarningListener@1018}
m_wasLastValueNull = false
m_cachedDataWrappers = {ArrayList@1019} size = 1
m_cursorPosition = {CursorPosition@1087} "AT_LAST"
m_columnNameIndexes = {ArrayList@1021} size = 1
m_numColumns = 1
m_parentStatement = {VerticaJdbc4PreparedStatementImpl@996}
m_jdbcVersion = {JDBCVersion@1022} "JDBC4"
m_streamBufferSize = 32000
Update3: SQL looks like this:
with prov as
(select ...
from ...
join ...
on ...
where ...)
,
debet as
(select prov....
from prov
where ...
group by prov....
),
kredit as
(select prov....
from prov
where ...
group by prov....
)
select
TO_CHAR(SUM(debet.sum_debet_rur)) SSS
from
kredit full join debet
on ...
where (debet...) and (debet....)
UNION ALL SELECT TO_CHAR(123) SSS from dual
rs
for the first row? – Dominik Sandjajars
afte the first call ofrs.next()
? – Moh-Aw