最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - What exception do we get from SQL Server and Sybase jdbc driver just like we get for Oracle JDBC driver-Numeric overflow

programmeradmin0浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 1

You 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;
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论