JDBC driver returns incorrect column size using getColumnDisplaySize (Doc ID 1299057.1)

Last updated on MARCH 30, 2015

Applies to:

JDBC - Version 11.1.0.7 and later
Information in this document applies to any platform.

Symptoms



JDBC application returns an incorrect column size using getColumnDisplaySize when using the JDBC OCI driver and JDBC thin version 11.1 and 11.2



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


public class TestOCI {

public static void main(String[] args) {

try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:oci:@xxx", "scott", "tiger");
//Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//yourHost/orcl", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select 12345 as id, '12345' as idStr , 'TEST' as testStr from dual");

// Get the ResultSet meta data
ResultSetMetaData rmd = rs.getMetaData();

if (rmd != null) {

int columnCount = rmd.getColumnCount();

for(int i=1; i<=columnCount; i++) {

// Display number of Column name
System.out.print("Column Name :" + rmd.getColumnName(i));

// Display number of Column Type
System.out.print(" Column Type :" + rmd.getColumnTypeName(i));

// Display number of Column size
System.out.println(" Column Size :" + rmd.getColumnDisplaySize (i));

}
}
}
catch(SQLException se){
System.out.println("SQLException ->"+se);
}
catch(Exception e){
System.out.println("Exception ->"+e);
}

}
}


Compiling and running the code:

$ORACLE_HOME/jdk/bin/javac -cp .:$ORACLE_HOME/jdbc/lib/ojdbc5.jar TestOCI.java
$ORACLE_HOME/jdk/bin/java -cp .:$ORACLE_HOME/jdbc/lib/ojdbc5.jar TestOCI

 

For the JDBC OCI cases, you will also need to ensure that the native libraries ( $ORACLE_HOME/lib or $ORACLE_HOME/lib32) are in the PATH (Windows) or LD_LIBRARY_PATH ( Linux, Solaris)


Results:


JDBC OCI 11.2.0.2:

Column Name :ID Column Type :NUMBER Column Size :4
Column Name :IDSTR Column Type :CHAR Column Size :5
Column Name :TESTSTR Column Type :CHAR Column Size :4

JDBC Thin 11.2.0.2:

Column Name :ID Column Type :NUMBER Column Size :22
Column Name :IDSTR Column Type :CHAR Column Size :5
Column Name :TESTSTR Column Type :CHAR Column Size :4

JDBC Thin 11.1.0.7:

Column Name :ID Column Type :NUMBER Column Size :22
Column Name :IDSTR Column Type :CHAR Column Size :5
Column Name :TESTSTR Column Type :CHAR Column Size :4



Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms