admin管理员组文章数量:1333662
I have a Spring Boot application in which I am connecting to SQL Server, Sybase, Oracle and MySQL database to get metadata details. While collecting rows count of a tables with below code in Oracle
Resultset.getlong("rowcount")
I'm getting below error
SQL exception - numeric overflow.
When the rowcount is greater than the long max value we are getting this error. Ideally, we don't want to throw the exception, we want to catch it and do some work around for it.
As like we got SQL exception with numeric overflow flow in Oracle, we want to know what kind of exception and message I will get for SQL Server and Sybase database servers.
We cannot create tables with that many rows in our dev environment database to test it.
I have a Spring Boot application in which I am connecting to SQL Server, Sybase, Oracle and MySQL database to get metadata details. While collecting rows count of a tables with below code in Oracle
Resultset.getlong("rowcount")
I'm getting below error
SQL exception - numeric overflow.
When the rowcount is greater than the long max value we are getting this error. Ideally, we don't want to throw the exception, we want to catch it and do some work around for it.
As like we got SQL exception with numeric overflow flow in Oracle, we want to know what kind of exception and message I will get for SQL Server and Sybase database servers.
We cannot create tables with that many rows in our dev environment database to test it.
Share Improve this question edited Nov 20, 2024 at 12:32 Mark Rotteveel 109k229 gold badges156 silver badges221 bronze badges asked Nov 20, 2024 at 12:24 Pavan GPavan G 1271 silver badge7 bronze badges 2- 1 You don't need to create a table with that many rows, you'll just need to query a value that is 2^63 or greater with a type that can hold such a value without overflow, and then request it with getLong. In any case, you're asking for two different products at the same time, which makes this question too broad. It will (or, should) be a SQLException, but the exact message, vendor code, etc, will be product-specific. – Mark Rotteveel Commented Nov 20, 2024 at 12:30
- Why not just change the return value to bigdecimal or something that can hold whatever row counts you can think of? – siggemannen Commented Nov 21, 2024 at 14:28
2 Answers
Reset to default 1You can create a virtual table with an arbitrary amount of rows using this
WITH SeqCTE AS (
SELECT 1 AS Seq
UNION ALL
SELECT Seq + 1
FROM SeqCTE
WHERE Seq < @newRows -- specify the desired number of rows
)
SELECT Seq
INTO #SequentialNumbers
FROM SeqCTE;
With this it should be able to try yourself what kind of exception you get.
Microsoft's JDBC driver's .getLong() throws SQLServerException:
SQLServerResultSet.java
@Override
public long getLong(int columnIndex) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getLong", columnIndex);
checkClosed();
Long value = (Long) getValue(columnIndex, JDBCType.BIGINT);
loggerExternal.exiting(getClassNameLogging(), "getLong", value);
return null != value ? value : 0;
}
本文标签:
版权声明:本文标题:java - What exception do we get from SQL Server and Sybase jdbc driver just like we get for Oracle JDBC driver-Numeric overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742357456a2459701.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论