Re: jdbc / getTables bug?

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: <pgsql-jdbc(at)postgresql(dot)org>, "Laurette Cisneros" <laurette(at)nextbus(dot)com>
Subject: Re: jdbc / getTables bug?
Date: 2001-06-18 20:17:14
Message-ID: 00ec01c0f833$aa2bed80$0201a8c0@INSPIRON
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Yes, this is a known problem and I believe has been fixed in cvs. If you
want you can pick up the jars from jdbc.fastcrypt.com

Dave
----- Original Message -----
From: "Laurette Cisneros" <laurette(at)nextbus(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Sent: Monday, June 18, 2001 3:04 PM
Subject: [JDBC] jdbc / getTables bug?

> Is anyone aware of a problem in the jdbc driver for the getTables()
> function when a view is present? I'm getting a null pointer exception:
> Exception caught.
> java.lang.NullPointerException
> java.lang.NullPointerException
> at
>
org.postgresql.jdbc2.DatabaseMetaData.getTables(DatabaseMetaData.java:1707)
> at mettst.doDatabaseMetaData(mettst.java:20)
> at mettst.<init>(mettst.java:73)
> at mettst.main(mettst.java:126)
>
> I'm using Postgresql version 7.1 and 7.1.2 and this occurs in both. This
> exception only occurs if a view is present.
>
> Here's the complete java code to reproduce this (this problem was
> encountered when I ran the metadata example that came with the jdbc dirver
> code was run against my database. I narrowed down a test for this problem
> using this example). Any ideas?
>
> Thanks.
>
> ---------------------------- 8< -----------------------------8<
> -----------------------------
>
> import java.io.*;
> import java.sql.*;
> import java.text.*;
>
> /**
> * Test jdbc view bug
> * To use it, simply have a database created. It will create some work
tables
> * and run tests on them.
> */
>
> public class mettst
> {
> Connection db; // The connection to the database
> Statement st; // Our statement to run queries with
> DatabaseMetaData dbmd; // This defines the structure of the
database
>
> public void doDatabaseMetaData() throws SQLException {
>
> displayResult(dbmd.getTables(null,null,null,null));
>
> }
>
> public void init() throws SQLException {
> System.out.println("Creating tables and view");
> cleanup();
> st.executeUpdate("create table x " +
> "(col1 text);");
> st.executeUpdate("create view vx as " +
> "select col1 " +
> "from x;");
> }
>
> public void cleanup() throws SQLException {
> System.out.println("Cleaning up...");
> try {
> st.executeUpdate("drop table x;");
> } catch(Exception ex) {
> // ignore any errors here
> }
> try {
> st.executeUpdate("drop view vx;");
> } catch(Exception ex) {
> // ignore any errors here
> }
> }
>
> public mettst() throws ClassNotFoundException, FileNotFoundException,
> IOException, SQLException
> {
> String url = "jdbc:postgresql://derby:5432/mettst";
> String usr = "user1";
> String pwd = "";
>
> // Load the driver
> Class.forName("org.postgresql.Driver");
>
> // Connect to database
> System.out.println("Connecting to Database URL = " + url);
> db = DriverManager.getConnection(url, usr, pwd);
>
> System.out.println("getMetaData()");
> dbmd = db.getMetaData();
> st = db.createStatement();
>
> // This prints the backend's version
> System.out.println("Connected to "+dbmd.getDatabaseProductName()+"
> "+dbmd.getDatabaseProductVersion());
>
> init();
>
> System.out.println("Now the test...");
>
> // Now the test
> doDatabaseMetaData();
>
> System.out.println("\nNow closing the connection");
> st.close();
> db.close();
>
> cleanup();
> }
>
> /**
> * This displays a result set.
> * Note: it closes the result once complete.
> */
> public void displayResult(ResultSet rs) throws SQLException
> {
> System.out.println("Dispay ResultSet");
> ResultSetMetaData rsmd = rs.getMetaData();
> int count=0;
>
> // Print the result column names
> int cols = rsmd.getColumnCount();
> for(int i=1;i<=cols;i++)
> System.out.print(rsmd.getColumnLabel(i)+(i<cols?"\t":"\n"));
>
> // now the results
> while(rs.next()) {
> count++;
> for(int i=1;i<=cols;i++) {
> Object o = rs.getObject(i);
> if(rs.wasNull())
> System.out.print("{null}"+(i<cols?"\t":"\n"));
> else
> System.out.print(o.toString()+(i<cols?"\t":"\n"));
> }
> }
>
> System.out.println("Result returned "+count+" rows.");
>
> // finally close the result set
> rs.close();
> }
>
> public static void main(String args[])
> {
> System.out.println("PostgreSQL metdata tester v6.4 rev 1\n");
>
> // This line outputs debug information to stderr. To enable this,
simply
> // add a parameter to the command line
> if(args.length>0)
> DriverManager.setLogStream(System.err);
>
> // Now run the tests
> try {
> mettst test = new mettst();
> } catch(Exception ex) {
> System.err.println("Exception caught.\n"+ex);
> ex.printStackTrace();
> }
> }
> }
>
>
> Laurette Cisneros
> NextBus Information Systems
> laurette(at)nextbus(dot)com
> (510) 420-3137
> Why wait?
> www.nextbus.com
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tum Khawcharoenporn 2001-06-18 21:08:27 JDBC Ant Problem
Previous Message Laurette Cisneros 2001-06-18 19:04:15 jdbc / getTables bug?