crystal reports varchar = string length 0 in jdbc but correct when jdbc-odbc bridge - Mailing list pgsql-jdbc

From Klint Gore
Subject crystal reports varchar = string length 0 in jdbc but correct when jdbc-odbc bridge
Date
Msg-id 402C388D166.66EEKG@129.180.47.120
Whole thread Raw
Responses Re: crystal reports varchar = string length 0 in jdbc but
List pgsql-jdbc
I've just started with crystal reports 10 and java based connections.
My problem is that when I use the postgres jdbc driver, my varchar's all
come out as string fields of length 0.  If I use the sun jdbc-odbc
bridge, then they come out the correct length.  int4, int2, timestamp,
date all come out correct on either driver.

Anyone got any suggestions?  Using java to walk the table writing values
can read the values ok (code below).  Has anyone got a class to show the
metadata for a table?

Using the JDBC driver, the javabean looks like this (the things in []
have been changed from their values) which appears to be correct as it
works for non string types.  I switch between the 2 connection methods
by commenting out the appropriate forName and getConnection.

import java.sql.*;

public class PostreSQLDataSourceBean {

   private ResultSet resultSet = null;
   private Connection con = null;
   private String urlj = "jdbc:postgresql://[ip]/[dbname]";
   private String urlo = "jdbc:odbc:[dsnname]";

   private String JDBCBridge = "sun.jdbc.odbc.JdbcOdbcDriver";
   private String JDBCConName = "org.postgresql.Driver";

   private String sqlQuery = "select * from pg_class";

   public PostreSQLDataSourceBean() {
      try {
         //Create a connection to database JDBC->ODBC
          Class.forName(JDBCBridge);
          con = DriverManager.getConnection(urlo, [user], [pass]);

         //Create a connection to database JDBC
         // Class.forName(JDBCConName);
         //  con = DriverManager.getConnection(urlj, [user], [pass]);
      }
      catch (ClassNotFoundException e) {
         System.err.println( "Driver not found: " + e + "\n" + e.getMessage() );
      }
      catch (SQLException e) {
         System.out.println("SQL Exception #" +
         e.getErrorCode() + " : " + e.getLocalizedMessage());
         e.printStackTrace();
      }
   }

   public ResultSet getResultSet() throws
   java.sql.SQLException {
      //Create an SQL statement to execute
      Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

      //Execute the select statement to populate the ResultSet
      resultSet = stmt.executeQuery(sqlQuery);
      return resultSet;
   }
}

I checked the data in java with the following code

    int numCols  = resultSet.getMetaData().getColumnCount();

    // print out the contents of the ResultSet
    while (resultSet.next()) {
      for (int j=1; j <= numCols; j++)
         System.out.print(resultSet.getString(j) + "  ");
      System.out.println();
    }


versions
jre j2re1.4.2_03
jsdk j2sdk1.4.2_03
jdbc pg74jdbc3.jar (downloaded yesterday 12th feb)
postgres 7.4 (not 7.4.1)

all the java is on my local w2k, the pg server is network rh 7.2 linux.



klint.

+---------------------------------------+-----------------+
: Klint Gore                            : "Non rhyming    :
: EMail   : kg@kgb.une.edu.au           :  slang - the    :
: Snail   : A.B.R.I.                    :  possibilities  :
: Mail      University of New England   :  are useless"   :
:           Armidale NSW 2351 Australia :     L.J.J.      :
: Fax     : +61 2 6772 5376             :                 :
+---------------------------------------+-----------------+

pgsql-jdbc by date:

Previous
From: Kris Jurka
Date:
Subject: Re: Cursors and transactions
Next
From: Kris Jurka
Date:
Subject: Re: crystal reports varchar = string length 0 in jdbc but