pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Toni Helenius <Toni.Helenius@syncrontech.com>
To: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: TEXT columns should indentify as java.sql.Types.CLOB
Date: Tue, 17 Aug 2010 10:08:12 +0300
Message-ID: <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com> (raw)
In-Reply-To: <4C695AED.5040806@ttc-cmc.net>
References: <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0DF3@ink.sad.syncrontech.com>
	<4C695AED.5040806@ttc-cmc.net>

Hi, 

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 columns 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 Java, that is correct. But I need to create a CREATE SQL dynamically from these accross different databases, mapping the fields (also utilizing our fixed field mappings). Reading the field values isn't necessary here. This is why I need the details on what kind of field in common SQL sense we are talking about. This provides pretty good database independency!

cols.getShort("DATA_TYPE");
returns the java.sql.Types enumeration. TEXT field returns VARCHAR. Which in my oppinion should be CLOB.

ResultSet cols = metaFrom.getColumns(null, userFrom, code, null);
userFrom = schema string; code = table name;


-----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 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 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 particular table. If your application needs to identify column types regardless of different databases then the way I do it is through evaluation of the table columns. Attached file containing the output for the last three or so PostgreSQL JDBC drivers. 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); }



view thread (14+ messages)  latest in thread

Message-ID: <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com>
Permalink:  ../E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com/
Also on:    postgresql.org/message-id/E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: Toni.Helenius@syncrontech.com, danap@ttc-cmc.net
  Subject: Re: TEXT columns should indentify as java.sql.Types.CLOB
  In-Reply-To: <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com>
  References: <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0DF3@ink.sad.syncrontech.com> <4C695AED.5040806@ttc-cmc.net> <E6A9CAA76548CB4EB02D2E3B174DD3B155381F0E4C@ink.sad.syncrontech.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox