Re: TEXT columns should indentify as java.sql.Types.CLOB - Mailing list pgsql-jdbc

From Toni Helenius
Subject Re: TEXT columns should indentify as java.sql.Types.CLOB
Date
Msg-id E6A9CAA76548CB4EB02D2E3B174DD3B155381F0EAE@ink.sad.syncrontech.com
Whole thread Raw
In response to Re: TEXT columns should indentify as java.sql.Types.CLOB  (dmp <danap@ttc-cmc.net>)
Responses Re: TEXT columns should indentify as java.sql.Types.CLOB
List pgsql-jdbc
Hi,

An definitely a bug: BOOLEAN columns get identified as java.sql.Types.VARCHAR. Not java.sql.Types.BOOLEAN as they
should.I end up getting SQL create statements where boolean fields are translated back as VARCHAR(1). 

-----Original Message-----
From: dmp [mailto:danap@ttc-cmc.net]
Sent: 16. elokuuta 2010 18:36
To: Toni Helenius; pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] TEXT columns should indentify as java.sql.Types.CLOB

>
>
>Hello,
>
>I'm using Postgres 8.3.11 database and the latest JDBC driver 8.4 Build 701 (JDBC 4) + Java 6. In our databases there
areTEXT type columns. However if I make a query to identify these fields in Java, the field DATA TYPE is VARCHAR and
thelength is 2147483647. Type name is correct; "TEXT". But as we need database independent code, we are using DATA TYPE
asI presume is correct. And I think these TEXT fields should return java.sql.Types.CLOB as DATA TYPE instead of
VARCHAR.
>
>Here is some code:
>
>Connection fromConn;
>DatabaseMetaData metaFrom;
>String userFrom;
>
>fromConn = from.getConnection();
>metaFrom = fromConn.getMetaData();
>userFrom = ((PooledConnection)from).getTableOwner();
>
>ResultSet cols = metaFrom.getColumns(null, userFrom, code, null); while
>(cols.next()) {
>    cols.getShort("DATA_TYPE");
>    cols.getString("TYPE_NAME");
>    }
>
I'm just not seeing it. Your code example seems to be collecting the information from the database connection not a
particulartable. If your application needs to identify column types regardless of different databases then the way I do
itis through evaluation of the table columns. Attached file containing the output for the last three or so PostgreSQL
JDBCdrivers. As far as TEXT and CLOB types I would prefer then to be identifed independently. 

danap

String sqlStatementString = "SELECT * FROM " + schemaTableName + " LIMIT 1"; ResultSet db_resultSet =
sqlStatement.executeQuery(sqlStatementString);
DatabaseMetaData dbMetaData = dbConnection.getMetaData(); ResultSetMetaData tableMetaData = db_resultSet.getMetaData();

for (int i = 1; i < tableMetaData.getColumnCount() + 1; i++) { // Collect Information on Column.

colNameString = tableMetaData.getColumnName(i); comboBoxNameString = parseColumnNameField(colNameString);
columnClass = tableMetaData.getColumnClassName(i);
columnType = tableMetaData.getColumnTypeName(i);
columnSize = Integer.valueOf(tableMetaData.getColumnDisplaySize(i));

System.out.println(i + " " + colNameString + " " + comboBoxNameString + " " + columnClass + " " + columnType + " " +
columnSize);} 

pgsql-jdbc by date:

Previous
From: Toni Helenius
Date:
Subject: Re: TEXT columns should indentify as java.sql.Types.CLOB
Next
From: Oliver Jowett
Date:
Subject: Re: TEXT columns should indentify as java.sql.Types.CLOB