Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle JDBC driver getDatabaseMetadata()["COLUMN_SIZE"] returns size in bytes (not in characters) for "BYTE" length semantics

smeshJun 14 2024

Description of getDatabaseMetadata()["COLUMN_SIZE"] in Javadoc:
"The COLUMN_SIZE column specifies the column size for the given column.
For character data, this is the ***length in characters***."

Scenario:
- Check that database encoding is multiple bytes per character.
- Create column with the definition VARCHAR2(4 BYTE).
- Try to insert 4 characters each of which is encoded as multiple bytes.
- DBMS correctly generates ORA-12899: value too large for column (actual: 8, maximum: 4)
- Issue: Oracle JDBC driver getDatabaseMetadata()["COLUMN_SIZE"] returns 4, should return 1.

Steps to reproduce:

select * from NLS_DATABASE_PARAMETERS where PARAMETER = 'NLS_CHARACTERSET'; 
-- NLS_LENGTH_SEMANTICS = BYTE 
-- NLS_CHARACTERSET = AL32UTF8 

create table T { 
C VARCHAR2(4 BYTE) 
); 

insert into T(C) values ('1234'); 
-- OK 

insert into T(C) values ('яяяя'); 
-- SQL Error: ORA-12899: value too large for column "T"."C" (actual: 8, maximum: 4) 

Write Java program where you get getDatabaseMetadata()["COLUMN_SIZE"]. 
-- It returns 4, should return 1.

Comments

Processing

Post Details

Added on Jun 14 2024
1 comment
114 views