Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2986B63223B for ; Tue, 17 Aug 2010 04:08:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 95684-07 for ; Tue, 17 Aug 2010 07:08:23 +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 6A0636321BA for ; Tue, 17 Aug 2010 04:08:23 -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 o7H78K58039038; Tue, 17 Aug 2010 10:08:20 +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; Tue, 17 Aug 2010 10:08:15 +0300 From: Toni Helenius To: dmp , "pgsql-jdbc@postgresql.org" Date: Tue, 17 Aug 2010 10:08:12 +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: Acs9WeyoEMFFHkEIRbyd4E6odBYYOAAfwlsg 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/57 X-Sequence-Number: 20860 Hi,=20 Thanks for the reply. Your code essentially does the same, except it relies= that the table has some data in it to return a line. My code asks for colu= mns in a certain table. It works as well. You get: text_type Text Type java.lang.String text 2147483647 You're not actually mapping the classes in a way we need to do in this case= . This tells me that I should read te TEXT field as java.lang.String to Jav= a, that is correct. But I need to create a CREATE SQL dynamically from thes= e accross different databases, mapping the fields (also utilizing our fixed= field mappings). Reading the field values isn't necessary here. This is wh= y I need the details on what kind of field in common SQL sense we are talki= ng about. This provides pretty good database independency! cols.getShort("DATA_TYPE"); returns the java.sql.Types enumeration. TEXT field returns VARCHAR. Which i= n my oppinion should be CLOB. ResultSet cols =3D metaFrom.getColumns(null, userFrom, code, null); userFrom =3D schema string; code =3D table name; -----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); }