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

From: Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: crystal reports varchar = string length 0 in jdbc but correct when jdbc-odbc bridge
Date: 2004-02-13 02:38:05
Message-ID: 402C388D166.66EEKG@129.180.47.120
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)kgb(dot)une(dot)edu(dot)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 : :
+---------------------------------------+-----------------+

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2004-02-13 03:15:12 Re: crystal reports varchar = string length 0 in jdbc but
Previous Message Kris Jurka 2004-02-13 01:58:08 Re: Cursors and transactions