Pavan G
Pavan G

Reputation: 127

What exception do we get from SQL Server and Sybase jdbc driver just like we get for Oracle JDBC driver-Numeric overflow exception from rs.getLong()

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.

Upvotes: 2

Views: 61

Answers (2)

StrayCatDBA
StrayCatDBA

Reputation: 2880

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

Upvotes: -1

Jens Schauder
Jens Schauder

Reputation: 81907

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.

Upvotes: 1

Related Questions