Skip to content

[QUESTION] How differentiate max and non-max types in ResultSet #1496

Open
@tormodatt

Description

@tormodatt

Question

From JDBC-spec:

    /**
     * Retrieves the designated column's SQL type.
...
     * @return SQL type from java.sql.Types
...
     */
    int getColumnType(int column) throws SQLException;

For columns of type charchar(max) I would then expect this to return -1 (java.sql.Types.LONGVARCHAR), but it returns 12 (java.sql.Types.VARCHAR). I debugged a little bit, and found that this is caused by this switch-case:

https://github.com/microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java#L138

r = -1 before that switch-case (which is what I would want).

The comment here gives a pointer to why this is done:

    // under Katmai map the max types to non max to be inline with DBMD.

https://github.com/microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java#L112

I guess DBMD is DatabaseMetaData, but still don't understand why this is done this way.

I can't find any other way to derminine whether a column in a resultset is varchar or longvarchar.

Same goes for the other max-types I guess.

I reason I ask this question is that I'm trying to do .getClob when the coloumn is varchar(max), and .getString if it's a normal varchar.

Relevant Issues and Pull Requests

I couldn't find any issues related to this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionUsed when a question is asked, as opposed to an issue being raised

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions