Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D35BC63274B for ; Wed, 18 Aug 2010 04:04:32 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 34139-08 for ; Wed, 18 Aug 2010 07:04:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from espresso1.syncrontech.com (espresso1.syncrontech.com [213.28.98.34]) by mail.postgresql.org (Postfix) with ESMTP id CCE2163243E for ; Wed, 18 Aug 2010 04:04:24 -0300 (ADT) Received: from ink.sad.syncrontech.com (ink.syncrontech.com [192.168.2.107]) by espresso1.syncrontech.com (8.14.4/8.14.4) with ESMTP id o7I74Llf049057; Wed, 18 Aug 2010 10:04:22 +0300 (EEST) (envelope-from Toni.Helenius@syncrontech.com) Received: from ink.sad.syncrontech.com ([192.168.2.107]) by ink.sad.syncrontech.com ([192.168.2.107]) with mapi; Wed, 18 Aug 2010 10:04:16 +0300 From: Toni Helenius To: dmp , "pgsql-jdbc@postgresql.org" Date: Wed, 18 Aug 2010 10:04:13 +0300 Subject: Re: TEXT columns should indentify as java.sql.Types.CLOB Thread-Topic: [JDBC] TEXT columns should indentify as java.sql.Types.CLOB Thread-Index: Acs9WeyoEMFFHkEIRbyd4E6odBYYOABSU9/w Message-ID: References: <4C695AED.5040806@ttc-cmc.net> In-Reply-To: <4C695AED.5040806@ttc-cmc.net> Accept-Language: en-US, fi-FI Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, fi-FI Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201008/58 X-Sequence-Number: 20861 Hi, An definitely a bug: BOOLEAN columns get identified as java.sql.Types.VARCH= AR. 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]=20 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 70= 1 (JDBC 4) + Java 6. In our databases there are TEXT type columns. However = if I make a query to identify these fields in Java, the field DATA TYPE is = VARCHAR and the length is 2147483647. Type name is correct; "TEXT". But as = we need database independent code, we are using DATA TYPE as I presume is c= orrect. 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 =3D from.getConnection(); >metaFrom =3D fromConn.getMetaData(); >userFrom =3D ((PooledConnection)from).getTableOwner(); > >ResultSet cols =3D metaFrom.getColumns(null, userFrom, code, null); while= =20 >(cols.next()) { > cols.getShort("DATA_TYPE"); > cols.getString("TYPE_NAME"); > } > I'm just not seeing it. Your code example seems to be collecting the inform= ation from the database connection not a particular table. If your applicat= ion needs to identify column types regardless of different databases then t= he way I do it is through evaluation of the table columns. Attached file co= ntaining the output for the last three or so PostgreSQL JDBC drivers. As fa= r as TEXT and CLOB types I would prefer then to be identifed independently. danap String sqlStatementString =3D "SELECT * FROM " + schemaTableName + " LIMIT = 1"; ResultSet db_resultSet =3D sqlStatement.executeQuery(sqlStatementString= ); DatabaseMetaData dbMetaData =3D dbConnection.getMetaData(); ResultSetMetaDa= ta tableMetaData =3D db_resultSet.getMetaData(); for (int i =3D 1; i < tableMetaData.getColumnCount() + 1; i++) { // Collect= Information on Column. colNameString =3D tableMetaData.getColumnName(i); comboBoxNameString =3D pa= rseColumnNameField(colNameString); columnClass =3D tableMetaData.getColumnClassName(i); columnType =3D tableMetaData.getColumnTypeName(i); columnSize =3D Integer.valueOf(tableMetaData.getColumnDisplaySize(i)); System.out.println(i + " " + colNameString + " " + comboBoxNameString + " "= + columnClass + " " + columnType + " " + columnSize); }