I am working on some software that has to create dummy entries in various databases (Oracle, DB2, SQLServer) temporarily. Every column in the the row is filled with random data.
The code uses java.sql.DataBaseMetaData class in java to get the COLUMN_SIZE attribute to figure out how large of a random string to store in the VARCHAR2 and other string column types.
DatabaseMetaData metadata = connection.getMetaData();
while (resultSet.next()) {
ResultSet resultSet = metadata.getColumns(...);
int size = resultSet.getInt("COLUMN_SIZE");
}
The problem is, at least in Oracle, I can't seem to figure out if a column length is being returned in bytes or characters. Also, depending on the encoding, characters are a different number of bytes. Combine all this, and I am getting some SQL errors because the strings that are trying to get inserted are too big. Am I missing something obvious?