pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC
25+ messages / 16 participants
[nested] [flat]

* JDBC
@ 2002-02-16 23:34 Michael Welter <mike@introspect.com>
  2002-02-17 00:56 ` Re: JDBC Barry Lind <barry@xythos.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Michael Welter @ 2002-02-16 23:34 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

I'm trying to use JDBC to extract data from a ResultSet.  Everything 
works fine except for columns defined as arrays.  The JDBC array type 
names are preceded by a "_" (_text, _float8, _date, _timestampz, etc.)

The exception I get is "Class names may not have _ in them. You supplied 
{0}".  This is with conn.addDataType( "_text","org.postgres.PGobject" );

I'm using Postgres 7.2.  I wasn't able to compile with j2sdk1.4 so I had 
to drop back to jdk1.3.

Does pg JDBC come with data handlers for arrays?  Is anyone else using 
arrays with JDBC?

Thanks for your help.
Mike








^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2002-02-16 23:34 JDBC Michael Welter <mike@introspect.com>
@ 2002-02-17 00:56 ` Barry Lind <barry@xythos.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Barry Lind @ 2002-02-17 00:56 UTC (permalink / raw)
  To: Michael Welter <mike@introspect.com>; +Cc: pgsql-general@postgresql.org; pgsql-jdbc

Michael,

I am not sure why you are using addDataType().  You should be able to 
just use getArray() and setArray() with the 7.2 driver.

thanks,
--Barry


Michael Welter wrote:
> I'm trying to use JDBC to extract data from a ResultSet.  Everything 
> works fine except for columns defined as arrays.  The JDBC array type 
> names are preceded by a "_" (_text, _float8, _date, _timestampz, etc.)
> 
> The exception I get is "Class names may not have _ in them. You supplied 
> {0}".  This is with conn.addDataType( "_text","org.postgres.PGobject" );
> 
> I'm using Postgres 7.2.  I wasn't able to compile with j2sdk1.4 so I had 
> to drop back to jdk1.3.
> 
> Does pg JDBC come with data handlers for arrays?  Is anyone else using 
> arrays with JDBC?
> 
> Thanks for your help.
> Mike
> 
> 
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org
> 





^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2002-12-11 21:40 Alvaro Escobar <escobar_alvaro@hotmail.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Alvaro Escobar @ 2002-12-11 21:40 UTC (permalink / raw)
  To: pgsql-jdbc


I'm new Postgrsql user and I'm trying to make the conection betwen two computers, one running win200 and java (for development) and another one whit Postgresql data base.

I'been trying to update tables with the JSP files but I can't connect with the data base, maybe the JDBC JAR file is not installed (I don't know how verify that).

What should I do????

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2003-01-14 12:26 Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-14 18:50 ` Re: JDBC Jeffrey Melloy <jmelloy@visualdistortion.org>
  0 siblings, 1 reply; 25+ messages in thread

From: Marcelo Pereira @ 2003-01-14 12:26 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

Hi All,

I have been working to make PostgreSQL acessible from java. I have
downloaded and instaled the following:

- j2sdk-1_4_1_01-linux-i586.bin
- jakarta-ant-1.5.1-src.tar.gz

and compiled PostgreSQL as:

# ./configure --with-java
# make
# make install

The driver (postgresql.jar) was compiled properly, and I have configured
some variables:

# export CLASSPATH=/usr/local/pgsql/share/java/postgresql.jar:.
# export ANT_HOME=/usr/local/ant
# export JAVA_HOME=/usr/local/j2sdk1.4.1
# export PATH=${JAVA_HOME}:${PATH}:${ANT_HOME}/bin

So I think the environment is almost good, but I can't compile a source
that use jdbc.

Would you send to me a really simple example java source code using jdbc,
acessing a simple table at PostgreSQL? I'm really having problem with
this.

Thanks in advance and
Best Regards,

Marcelo Pereira

-- Remember that only God and ^[:w saves.
        __
       (_.\           © Marcelo Pereira     |
        / / ___       marcelo@pereira.com   |
       / (_/ _ \__    [Math|99]-IMECC       |
_______\____/_\___)___Unicamp_______________/




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2003-01-14 12:26 JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
@ 2003-01-14 18:50 ` Jeffrey Melloy <jmelloy@visualdistortion.org>
  2003-01-15 13:08   ` Re: JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  0 siblings, 1 reply; 25+ messages in thread

From: Jeffrey Melloy @ 2003-01-14 18:50 UTC (permalink / raw)
  To: Marcelo Pereira <gandalf@sum.desktop.com.br>; +Cc: pgsql-general@postgresql.org

Marcelo Pereira wrote:

>Would you send to me a really simple example java source code using jdbc,
>acessing a simple table at PostgreSQL
>

Giving credit where credit is due, this is Mark Liyanage's simple java 
program, from www.entorpy.ch.  It was written for OS X, but there 
shouldn't be a problem.

/*
 * TestPostgreSQL.java
 *
 * 
 * History:
 * 
 * When         Who               What
 * ==============================================================================
 * 2001-06-23   Marc Liyanage     First version
 *
 *
 * License:
 *
 * Copyright abandoned 2001 by Marc Liyanage
 * Do with this whatever you want.
 *
 */

import java.sql.*;

/**
 * The TestPostgreSQL class shows how to access the PostgreSQL
 * DB server on Mac OS X using the JDBC interface.
 * It assumes the installation has been performed according
 * to the instructions at http://www.entropy.ch/software/macosx/postgresql.
 *
 *
 * You compile it like this:
 *
 *   % javac TestPostgreSQL.java
 *
 * Make sure that the PostgreSQL server has been
 * started with the -i flag. This is not the case in
 * the example lines of the installation instructions mentioned
 * above and in the StartupItem package that's available
 * from the same location. The -i flag tells the DB server
 * to listen for connection requests from the network
 * and I have left it off by default for security reasons.
 *
 * If the server is running correctly (with -i), run the Test like this:
 * (in the same directory where you compiled the example)
 *
 *   % java -classpath /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL
 *
 * You should see the current date as returned by the DB server:
 * 
 *   2001-06-23 16:31:49+02
 *
 *
 * @author   Marc Liyanage
 * @version  1.0
 */
public class TestPostgreSQL {


	public static void main(String argv[]) throws Exception {
		
		// Load the driver class
		//
		Class.forName("org.postgresql.Driver");
		
		// Try to connect to the DB server.
		// We tell JDBC to use the "postgresql" driver
		// and to connect to the "template1" database
		// which should always exist in PostgreSQL.
		// We use the username "postgres" and no
		// password to connect. Since we're not accessing
		// any tables but only an SQL function
		// this should work.
		//
		Connection conn = DriverManager.getConnection(
			"jdbc:postgresql:template1",
			"postgres",
			""
		);
		
		// Set up and run a query that fetches
		// the current date using the "now()" PostgreSQL function.
		// 
		Statement stmt = conn.createStatement();
		ResultSet rset = stmt.executeQuery("SELECT now();");

		// Iterate through the rows of the result set
		// (obviously only one row in this example) and
		// print each one.
		//
		while (rset.next()) {
			System.out.println(rset.getString(1));
		}    
	
		// Close result set, statement and DB connection
		//
		rset.close();
		stmt.close();
		conn.close();

	}


}








^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2003-01-14 12:26 JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-14 18:50 ` Re: JDBC Jeffrey Melloy <jmelloy@visualdistortion.org>
@ 2003-01-15 13:08   ` Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-15 12:55     ` Re: [JDBC] JDBC Dave Cramer <Dave@micro-automation.net>
  0 siblings, 1 reply; 25+ messages in thread

From: Marcelo Pereira @ 2003-01-15 13:08 UTC (permalink / raw)
  To: Jeffrey Melloy <jmelloy@visualdistortion.org>; +Cc: pgsql-general@postgresql.org; pgsql-jdbc

Hi Jeffrey,

Thanks for your example code. I have compiled it without any problem, but
when I try to run I have the following:

$ javac TestPostgreSQL.java
$ java TestPostgreSQL.class
Exception in thread 
"main" java.lang.NoClassDefFoundError: TestPostgreSQL/class

$ java -classpath
/usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL.class
Exception in thread
"main" java.lang.NoClassDefFoundError: TestPostgreSQL/class

$ export CLASSPATH=/usr/local/pgsql/share/java/postgresql.jar:.
$ java TestPostgreSQL.class
Exception in thread
"main" java.lang.NoClassDefFoundError: TestPostgreSQL/class

As you can see I have this problem, whatever I try to do. So I thought my
JDBC driver wasn't properly compiled, so I have downloaded the 7.3 JDBC
driver from PostgreSQL.org (pg73jdbc1.jar) and run all the tests above,
always with the same problem.

What am I doing wrong??

Thanks in advance and
Best Regards,

Marcelo Pereira

-- Remember that only God and ^[:w saves.
        __
       (_.\           © Marcelo Pereira     |
        / / ___       marcelo@pereira.com   |
       / (_/ _ \__    [Math|99]-IMECC       |
_______\____/_\___)___Unicamp_______________/

--- Jeffrey Melloy, with his fast fingers, wrote:

:> Marcelo Pereira wrote:
:> 
:> >Would you send to me a really simple example java source code using jdbc,
:> >acessing a simple table at PostgreSQL
:> >
:> 
:> Giving credit where credit is due, this is Mark Liyanage's simple java 
:> program, from www.entorpy.ch.  It was written for OS X, but there 
:> shouldn't be a problem.
:> 
:> /*
:>  * TestPostgreSQL.java
:>  *
:>  * 
:>  * History:
:>  * 
:>  * When         Who               What
:>  * ==============================================================================
:>  * 2001-06-23   Marc Liyanage     First version
:>  *
:>  *
:>  * License:
:>  *
:>  * Copyright abandoned 2001 by Marc Liyanage
:>  * Do with this whatever you want.
:>  *
:>  */
:> 
:> import java.sql.*;
:> 
:> /**
:>  * The TestPostgreSQL class shows how to access the PostgreSQL
:>  * DB server on Mac OS X using the JDBC interface.
:>  * It assumes the installation has been performed according
:>  * to the instructions at http://www.entropy.ch/software/macosx/postgresql.
:>  *
:>  *
:>  * You compile it like this:
:>  *
:>  *   % javac TestPostgreSQL.java
:>  *
:>  * Make sure that the PostgreSQL server has been
:>  * started with the -i flag. This is not the case in
:>  * the example lines of the installation instructions mentioned
:>  * above and in the StartupItem package that's available
:>  * from the same location. The -i flag tells the DB server
:>  * to listen for connection requests from the network
:>  * and I have left it off by default for security reasons.
:>  *
:>  * If the server is running correctly (with -i), run the Test like this:
:>  * (in the same directory where you compiled the example)
:>  *
:>  *   % java -classpath /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL
:>  *
:>  * You should see the current date as returned by the DB server:
:>  * 
:>  *   2001-06-23 16:31:49+02
:>  *
:>  *
:>  * @author   Marc Liyanage
:>  * @version  1.0
:>  */
:> public class TestPostgreSQL {
:> 
:> 
:> 	public static void main(String argv[]) throws Exception {
:> 		
:> 		// Load the driver class
:> 		//
:> 		Class.forName("org.postgresql.Driver");
:> 		
:> 		// Try to connect to the DB server.
:> 		// We tell JDBC to use the "postgresql" driver
:> 		// and to connect to the "template1" database
:> 		// which should always exist in PostgreSQL.
:> 		// We use the username "postgres" and no
:> 		// password to connect. Since we're not accessing
:> 		// any tables but only an SQL function
:> 		// this should work.
:> 		//
:> 		Connection conn = DriverManager.getConnection(
:> 			"jdbc:postgresql:template1",
:> 			"postgres",
:> 			""
:> 		);
:> 		
:> 		// Set up and run a query that fetches
:> 		// the current date using the "now()" PostgreSQL function.
:> 		// 
:> 		Statement stmt = conn.createStatement();
:> 		ResultSet rset = stmt.executeQuery("SELECT now();");
:> 
:> 		// Iterate through the rows of the result set
:> 		// (obviously only one row in this example) and
:> 		// print each one.
:> 		//
:> 		while (rset.next()) {
:> 			System.out.println(rset.getString(1));
:> 		}    
:> 	
:> 		// Close result set, statement and DB connection
:> 		//
:> 		rset.close();
:> 		stmt.close();
:> 		conn.close();
:> 
:> 	}
:> 
:> 
:> }
:> 
:> 
:> 
:> 
:> 
:> 
:> ---------------------------(end of broadcast)---------------------------
:> TIP 6: Have you searched our list archives?
:> 
:> http://archives.postgresql.org
:> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: [JDBC] JDBC
  2003-01-14 12:26 JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-14 18:50 ` Re: JDBC Jeffrey Melloy <jmelloy@visualdistortion.org>
  2003-01-15 13:08   ` Re: JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
@ 2003-01-15 12:55     ` Dave Cramer <Dave@micro-automation.net>
  2003-01-15 14:17       ` Re: [JDBC] JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  0 siblings, 1 reply; 25+ messages in thread

From: Dave Cramer @ 2003-01-15 12:55 UTC (permalink / raw)
  To: Marcelo Pereira <gandalf@sum.desktop.com.br>; +Cc: Jeffrey Melloy <jmelloy@visualdistortion.org>; pgsql-general@postgresql.org <pgsql-general@postgresql.org>; pgsql-jdbc

Marcelo,

Just type

java TestPostreSQL

to run it

Dave
On Wed, 2003-01-15 at 08:08, Marcelo Pereira wrote:
> Hi Jeffrey,
> 
> Thanks for your example code. I have compiled it without any problem, but
> when I try to run I have the following:
> 
> $ javac TestPostgreSQL.java
> $ java TestPostgreSQL.class
> Exception in thread 
> "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
> 
> $ java -classpath
> /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL.class
> Exception in thread
> "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
> 
> $ export CLASSPATH=/usr/local/pgsql/share/java/postgresql.jar:.
> $ java TestPostgreSQL.class
> Exception in thread
> "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
> 
> As you can see I have this problem, whatever I try to do. So I thought my
> JDBC driver wasn't properly compiled, so I have downloaded the 7.3 JDBC
> driver from PostgreSQL.org (pg73jdbc1.jar) and run all the tests above,
> always with the same problem.
> 
> What am I doing wrong??
> 
> Thanks in advance and
> Best Regards,
> 
> Marcelo Pereira
> 
> -- Remember that only God and ^[:w saves.
>         __
>        (_.\           © Marcelo Pereira     |
>         / / ___       marcelo@pereira.com   |
>        / (_/ _ \__    [Math|99]-IMECC       |
> _______\____/_\___)___Unicamp_______________/
> 
> --- Jeffrey Melloy, with his fast fingers, wrote:
> 
> :> Marcelo Pereira wrote:
> :> 
> :> >Would you send to me a really simple example java source code using jdbc,
> :> >acessing a simple table at PostgreSQL
> :> >
> :> 
> :> Giving credit where credit is due, this is Mark Liyanage's simple java 
> :> program, from www.entorpy.ch.  It was written for OS X, but there 
> :> shouldn't be a problem.
> :> 
> :> /*
> :>  * TestPostgreSQL.java
> :>  *
> :>  * 
> :>  * History:
> :>  * 
> :>  * When         Who               What
> :>  * ==============================================================================
> :>  * 2001-06-23   Marc Liyanage     First version
> :>  *
> :>  *
> :>  * License:
> :>  *
> :>  * Copyright abandoned 2001 by Marc Liyanage
> :>  * Do with this whatever you want.
> :>  *
> :>  */
> :> 
> :> import java.sql.*;
> :> 
> :> /**
> :>  * The TestPostgreSQL class shows how to access the PostgreSQL
> :>  * DB server on Mac OS X using the JDBC interface.
> :>  * It assumes the installation has been performed according
> :>  * to the instructions at http://www.entropy.ch/software/macosx/postgresql.
> :>  *
> :>  *
> :>  * You compile it like this:
> :>  *
> :>  *   % javac TestPostgreSQL.java
> :>  *
> :>  * Make sure that the PostgreSQL server has been
> :>  * started with the -i flag. This is not the case in
> :>  * the example lines of the installation instructions mentioned
> :>  * above and in the StartupItem package that's available
> :>  * from the same location. The -i flag tells the DB server
> :>  * to listen for connection requests from the network
> :>  * and I have left it off by default for security reasons.
> :>  *
> :>  * If the server is running correctly (with -i), run the Test like this:
> :>  * (in the same directory where you compiled the example)
> :>  *
> :>  *   % java -classpath /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL
> :>  *
> :>  * You should see the current date as returned by the DB server:
> :>  * 
> :>  *   2001-06-23 16:31:49+02
> :>  *
> :>  *
> :>  * @author   Marc Liyanage
> :>  * @version  1.0
> :>  */
> :> public class TestPostgreSQL {
> :> 
> :> 
> :> 	public static void main(String argv[]) throws Exception {
> :> 		
> :> 		// Load the driver class
> :> 		//
> :> 		Class.forName("org.postgresql.Driver");
> :> 		
> :> 		// Try to connect to the DB server.
> :> 		// We tell JDBC to use the "postgresql" driver
> :> 		// and to connect to the "template1" database
> :> 		// which should always exist in PostgreSQL.
> :> 		// We use the username "postgres" and no
> :> 		// password to connect. Since we're not accessing
> :> 		// any tables but only an SQL function
> :> 		// this should work.
> :> 		//
> :> 		Connection conn = DriverManager.getConnection(
> :> 			"jdbc:postgresql:template1",
> :> 			"postgres",
> :> 			""
> :> 		);
> :> 		
> :> 		// Set up and run a query that fetches
> :> 		// the current date using the "now()" PostgreSQL function.
> :> 		// 
> :> 		Statement stmt = conn.createStatement();
> :> 		ResultSet rset = stmt.executeQuery("SELECT now();");
> :> 
> :> 		// Iterate through the rows of the result set
> :> 		// (obviously only one row in this example) and
> :> 		// print each one.
> :> 		//
> :> 		while (rset.next()) {
> :> 			System.out.println(rset.getString(1));
> :> 		}    
> :> 	
> :> 		// Close result set, statement and DB connection
> :> 		//
> :> 		rset.close();
> :> 		stmt.close();
> :> 		conn.close();
> :> 
> :> 	}
> :> 
> :> 
> :> }
> :> 
> :> 
> :> 
> :> 
> :> 
> :> 
> :> ---------------------------(end of broadcast)---------------------------
> :> TIP 6: Have you searched our list archives?
> :> 
> :> http://archives.postgresql.org
> :> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org
-- 
Dave Cramer <Dave@micro-automation.net>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: [JDBC] JDBC
  2003-01-14 12:26 JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-14 18:50 ` Re: JDBC Jeffrey Melloy <jmelloy@visualdistortion.org>
  2003-01-15 13:08   ` Re: JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
  2003-01-15 12:55     ` Re: [JDBC] JDBC Dave Cramer <Dave@micro-automation.net>
@ 2003-01-15 14:17       ` Marcelo Pereira <gandalf@sum.desktop.com.br>
  0 siblings, 0 replies; 25+ messages in thread

From: Marcelo Pereira @ 2003-01-15 14:17 UTC (permalink / raw)
  To: Dave Cramer <Dave@micro-automation.net>; +Cc: Jeffrey Melloy <jmelloy@visualdistortion.org>; pgsql-general@postgresql.org <pgsql-general@postgresql.org>; pgsql-jdbc

Hi Jeffrey, Dave and All,

Thanks for your answer, I got it running!

Thanks and Best Regards,

Marcelo Pereira

-- Remember that only God and ^[:w saves.
        __
       (_.\           © Marcelo Pereira     |
        / / ___       marcelo@pereira.com   |
       / (_/ _ \__    [Math|99]-IMECC       |
_______\____/_\___)___Unicamp_______________/

--- Dave Cramer, with his fast fingers, wrote:

:> Marcelo,
:> 
:> Just type
:> 
:> java TestPostreSQL
:> 
:> to run it
:> 
:> Dave
:> On Wed, 2003-01-15 at 08:08, Marcelo Pereira wrote:
:> > Hi Jeffrey,
:> > 
:> > Thanks for your example code. I have compiled it without any problem, but
:> > when I try to run I have the following:
:> > 
:> > $ javac TestPostgreSQL.java
:> > $ java TestPostgreSQL.class
:> > Exception in thread 
:> > "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
:> > 
:> > $ java -classpath
:> > /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL.class
:> > Exception in thread
:> > "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
:> > 
:> > $ export CLASSPATH=/usr/local/pgsql/share/java/postgresql.jar:.
:> > $ java TestPostgreSQL.class
:> > Exception in thread
:> > "main" java.lang.NoClassDefFoundError: TestPostgreSQL/class
:> > 
:> > As you can see I have this problem, whatever I try to do. So I thought my
:> > JDBC driver wasn't properly compiled, so I have downloaded the 7.3 JDBC
:> > driver from PostgreSQL.org (pg73jdbc1.jar) and run all the tests above,
:> > always with the same problem.
:> > 
:> > What am I doing wrong??
:> > 
:> > Thanks in advance and
:> > Best Regards,
:> > 
:> > Marcelo Pereira
:> > 
:> > -- Remember that only God and ^[:w saves.
:> >         __
:> >        (_.\           © Marcelo Pereira     |
:> >         / / ___       marcelo@pereira.com   |
:> >        / (_/ _ \__    [Math|99]-IMECC       |
:> > _______\____/_\___)___Unicamp_______________/
:> > 
:> > --- Jeffrey Melloy, with his fast fingers, wrote:
:> > 
:> > :> Marcelo Pereira wrote:
:> > :> 
:> > :> >Would you send to me a really simple example java source code using jdbc,
:> > :> >acessing a simple table at PostgreSQL
:> > :> >
:> > :> 
:> > :> Giving credit where credit is due, this is Mark Liyanage's simple java 
:> > :> program, from www.entorpy.ch.  It was written for OS X, but there 
:> > :> shouldn't be a problem.
:> > :> 
:> > :> /*
:> > :>  * TestPostgreSQL.java
:> > :>  *
:> > :>  * 
:> > :>  * History:
:> > :>  * 
:> > :>  * When         Who               What
:> > :>  * ==============================================================================
:> > :>  * 2001-06-23   Marc Liyanage     First version
:> > :>  *
:> > :>  *
:> > :>  * License:
:> > :>  *
:> > :>  * Copyright abandoned 2001 by Marc Liyanage
:> > :>  * Do with this whatever you want.
:> > :>  *
:> > :>  */
:> > :> 
:> > :> import java.sql.*;
:> > :> 
:> > :> /**
:> > :>  * The TestPostgreSQL class shows how to access the PostgreSQL
:> > :>  * DB server on Mac OS X using the JDBC interface.
:> > :>  * It assumes the installation has been performed according
:> > :>  * to the instructions at http://www.entropy.ch/software/macosx/postgresql.
:> > :>  *
:> > :>  *
:> > :>  * You compile it like this:
:> > :>  *
:> > :>  *   % javac TestPostgreSQL.java
:> > :>  *
:> > :>  * Make sure that the PostgreSQL server has been
:> > :>  * started with the -i flag. This is not the case in
:> > :>  * the example lines of the installation instructions mentioned
:> > :>  * above and in the StartupItem package that's available
:> > :>  * from the same location. The -i flag tells the DB server
:> > :>  * to listen for connection requests from the network
:> > :>  * and I have left it off by default for security reasons.
:> > :>  *
:> > :>  * If the server is running correctly (with -i), run the Test like this:
:> > :>  * (in the same directory where you compiled the example)
:> > :>  *
:> > :>  *   % java -classpath /usr/local/pgsql/share/java/postgresql.jar:. TestPostgreSQL
:> > :>  *
:> > :>  * You should see the current date as returned by the DB server:
:> > :>  * 
:> > :>  *   2001-06-23 16:31:49+02
:> > :>  *
:> > :>  *
:> > :>  * @author   Marc Liyanage
:> > :>  * @version  1.0
:> > :>  */
:> > :> public class TestPostgreSQL {
:> > :> 
:> > :> 
:> > :> 	public static void main(String argv[]) throws Exception {
:> > :> 		
:> > :> 		// Load the driver class
:> > :> 		//
:> > :> 		Class.forName("org.postgresql.Driver");
:> > :> 		
:> > :> 		// Try to connect to the DB server.
:> > :> 		// We tell JDBC to use the "postgresql" driver
:> > :> 		// and to connect to the "template1" database
:> > :> 		// which should always exist in PostgreSQL.
:> > :> 		// We use the username "postgres" and no
:> > :> 		// password to connect. Since we're not accessing
:> > :> 		// any tables but only an SQL function
:> > :> 		// this should work.
:> > :> 		//
:> > :> 		Connection conn = DriverManager.getConnection(
:> > :> 			"jdbc:postgresql:template1",
:> > :> 			"postgres",
:> > :> 			""
:> > :> 		);
:> > :> 		
:> > :> 		// Set up and run a query that fetches
:> > :> 		// the current date using the "now()" PostgreSQL function.
:> > :> 		// 
:> > :> 		Statement stmt = conn.createStatement();
:> > :> 		ResultSet rset = stmt.executeQuery("SELECT now();");
:> > :> 
:> > :> 		// Iterate through the rows of the result set
:> > :> 		// (obviously only one row in this example) and
:> > :> 		// print each one.
:> > :> 		//
:> > :> 		while (rset.next()) {
:> > :> 			System.out.println(rset.getString(1));
:> > :> 		}    
:> > :> 	
:> > :> 		// Close result set, statement and DB connection
:> > :> 		//
:> > :> 		rset.close();
:> > :> 		stmt.close();
:> > :> 		conn.close();
:> > :> 
:> > :> 	}
:> > :> 
:> > :> 
:> > :> }
:> > :> 
:> > :> 
:> > :> 
:> > :> 
:> > :> 
:> > :> 
:> > :> ---------------------------(end of broadcast)---------------------------
:> > :> TIP 6: Have you searched our list archives?
:> > :> 
:> > :> http://archives.postgresql.org
:> > :> 
:> > 
:> > 
:> > ---------------------------(end of broadcast)---------------------------
:> > TIP 6: Have you searched our list archives?
:> > 
:> > http://archives.postgresql.org
:> -- 
:> Dave Cramer <Dave@micro-automation.net>
:> 
:> 
:> ---------------------------(end of broadcast)---------------------------
:> TIP 2: you can get off all lists at once with the unregister command
:>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
:> 




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2003-03-20 11:37 Maicol <maicol@wiz.com.br>
  0 siblings, 0 replies; 25+ messages in thread

From: Maicol @ 2003-03-20 11:37 UTC (permalink / raw)
  To: pgsql-jdbc

Please,

Normally i get the .tar file and decompile it in linux geting the .jar to use in java code.
I really not undestanding how to do it. 
Could you help me, please?


Best Regard,
MaicolAguiar

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2003-04-08 17:44 Sohail A. Khan <Sohail.A.Khan@student.shu.ac.uk>
  2003-04-08 18:33 ` Re: JDBC Dave Cramer <Dave@micro-automation.net>
  0 siblings, 1 reply; 25+ messages in thread

From: Sohail A. Khan @ 2003-04-08 17:44 UTC (permalink / raw)
  To: pgsql-jdbc

i have a real big problem understanding JDBC, here is the situation, i have a database in Microsoft
Access which consists of 3 tables with the following details:
*Student Details: ID, Name, Address, Course, Year of Study
*Course Details: Name of Course, Total number of students, units taught
*Staff Table: Name, Room, email, Units Delivered
 
(i have used ODBC)

Q1 - how do i extract information from the database in JAVA Applet
Q2 - how do produce a username and password to get access to the database
Q3 -  how do create queries

CAN U PLEASE HELP ME WITH THIS PROBLEM!
I WILL BE MOST GREATFUL IF U CAN SEND ME EXAMPLES AND STEP BY STEP HELP ON HOW TO PERFORM THE ABOVE
QUESTIONS

THANKS




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2003-04-08 17:44 JDBC Sohail A. Khan <Sohail.A.Khan@student.shu.ac.uk>
@ 2003-04-08 18:33 ` Dave Cramer <Dave@micro-automation.net>
  0 siblings, 0 replies; 25+ messages in thread

From: Dave Cramer @ 2003-04-08 18:33 UTC (permalink / raw)
  To: Sohail A. Khan <Sohail.A.Khan@student.shu.ac.uk>; +Cc: pgsql-jdbc

There is a jdbc-odbc bridge which you will need to use, odbc is very
much like jdbc.

Dave
On Tue, 2003-04-08 at 13:44, Sohail A. Khan wrote:
> i have a real big problem understanding JDBC, here is the situation, i have a database in Microsoft
> Access which consists of 3 tables with the following details:
> *Student Details: ID, Name, Address, Course, Year of Study
> *Course Details: Name of Course, Total number of students, units taught
> *Staff Table: Name, Room, email, Units Delivered
>  
> (i have used ODBC)
> 
> Q1 - how do i extract information from the database in JAVA Applet
> Q2 - how do produce a username and password to get access to the database
> Q3 -  how do create queries
> 
> CAN U PLEASE HELP ME WITH THIS PROBLEM!
> I WILL BE MOST GREATFUL IF U CAN SEND ME EXAMPLES AND STEP BY STEP HELP ON HOW TO PERFORM THE ABOVE
> QUESTIONS
> 
> THANKS
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
-- 
Dave Cramer <Dave@micro-automation.net>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2003-08-04 17:55 Lufkin, Brad <brad.lufkin@ngc.com>
  2003-08-04 21:05 ` Re: JDBC Nick Fankhauser <nickf@ontko.com>
  2003-08-04 21:06 ` Re: JDBC Kris Jurka <books@ejurka.com>
  0 siblings, 2 replies; 25+ messages in thread

From: Lufkin, Brad @ 2003-08-04 17:55 UTC (permalink / raw)
  To: pgsql-jdbc

Where can I get the Postgres JDBC jar files? When I try to download them
from the downloads page, I get a page with garbage on it and no file dialog
to save anything. What gives?



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2003-08-04 17:55 JDBC Lufkin, Brad <brad.lufkin@ngc.com>
@ 2003-08-04 21:05 ` Nick Fankhauser <nickf@ontko.com>
  1 sibling, 0 replies; 25+ messages in thread

From: Nick Fankhauser @ 2003-08-04 21:05 UTC (permalink / raw)
  To: Lufkin, Brad <brad.lufkin@ngc.com>; pgsql-jdbc

Brad-

It sounds like your browser doesn't recognize .jar files as something to
download rather than display. The way you fix this this depends on your
browser, but to get around the problem for now, try a right-click, "save
target as"

-Nick

> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Lufkin, Brad
> Sent: Monday, August 04, 2003 12:56 PM
> To: 'pgsql-jdbc@postgresql.org'
> Subject: [JDBC] JDBC
>
>
> Where can I get the Postgres JDBC jar files? When I try to download them
> from the downloads page, I get a page with garbage on it and no
> file dialog
> to save anything. What gives?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2003-08-04 17:55 JDBC Lufkin, Brad <brad.lufkin@ngc.com>
@ 2003-08-04 21:06 ` Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 25+ messages in thread

From: Kris Jurka @ 2003-08-04 21:06 UTC (permalink / raw)
  To: Lufkin, Brad <brad.lufkin@ngc.com>; +Cc: pgsql-jdbc



On Mon, 4 Aug 2003, Lufkin, Brad wrote:

> Where can I get the Postgres JDBC jar files? When I try to download them
> from the downloads page, I get a page with garbage on it and no file dialog
> to save anything. What gives?

The jdbc.postgresql.org web server is incorrectly configured and responds
with a Content-Type: text/plain header for the jar file, so your browser
is trying to display it as text.  Try right clicking on the link to the
jar file and selecting "Save Link Target As..." or something similar.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* JDBC
@ 2004-08-24 14:50 Hanna Tapani <tapani@kth.se>
  2004-08-24 15:16 ` Re: JDBC Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 25+ messages in thread

From: Hanna Tapani @ 2004-08-24 14:50 UTC (permalink / raw)
  To: pgsql-jdbc


Hi,

I've downloaded the pg74.215.jdbc3.jar-driver (I run  jdk 1.4). Do I now
have to install or build it or is it ready for use? I've tried pointing it
out with a classpath and loaded it with
"Class.forName("org.postgresql.Driver")". I get an exception but I don't
why.

/Hanna




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2004-08-24 14:50 JDBC Hanna Tapani <tapani@kth.se>
@ 2004-08-24 15:16 ` Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Kris Jurka @ 2004-08-24 15:16 UTC (permalink / raw)
  To: Hanna Tapani <tapani@kth.se>; +Cc: pgsql-jdbc



On Tue, 24 Aug 2004, Hanna Tapani wrote:

> I've downloaded the pg74.215.jdbc3.jar-driver (I run  jdk 1.4). Do I now
> have to install or build it or is it ready for use? I've tried pointing it
> out with a classpath and loaded it with
> "Class.forName("org.postgresql.Driver")". I get an exception but I don't
> why.

You don't need to do anything other than make the jar file available to
your application via the classpath which I would guess is not set
correctly in this case.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
@ 2018-06-10 20:24 Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:40 ` Re: JDBC Tom Lane <tgl@sss.pgh.pa.us>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 25+ messages in thread

From: Chuck Davis @ 2018-06-10 20:24 UTC (permalink / raw)
  To: pgsql-jdbc

I created a new, empty database and I want to test whether a table
exists or not.  I've googled and thought what I read @ stackoverflow
indicated the following should let me know (I've also seen the same at
other sites):

At instantiation result is set to false.

    private boolean checkEntity()
        // this checks whether this is a new database and tables have
not yet been created and prevent a null pointer exception
        // entities table must exist to use the system
        try {
            stat = connection.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
null, ex);
        }

        try {
            result = stat.execute("select exists (select 1 from
information_schema.tables where table_name = 'entities')");
            System.out.println("the checkEntity returned a result of "
+ result);
        } catch (SQLException ex) {
            Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
null, ex);
            result = false;
            return result;
        }

        return result;

    }

Even though no objects have been created in the database this result
is always returned true.  The documentation says the
information_schema is unique for each database so this statement
should return false until the table is created....I think.

I've also used this version with the same result:
            result = stat.execute("SELECT EXISTS (SELECT 1 FROM
information_schema.tables WHERE table_schema = 'jpl' AND table_name =
'entities')");

The only thing I can think of is that the information_schema is
actually for the cluster.  I have other databases in the cluster that
do have an entities table.

Any direction will be appreciated.




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
@ 2018-06-10 20:40 ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-06-10 23:05   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  1 sibling, 1 reply; 25+ messages in thread

From: Tom Lane @ 2018-06-10 20:40 UTC (permalink / raw)
  To: Chuck Davis <cjgunzel@gmail.com>; +Cc: pgsql-jdbc

Chuck Davis <cjgunzel@gmail.com> writes:
> I created a new, empty database and I want to test whether a table
> exists or not.

Are you sure the DB is in fact empty?

> The only thing I can think of is that the information_schema is
> actually for the cluster.

It is not.

> I have other databases in the cluster that
> do have an entities table.

I'm betting that you created such a table in template1, so that it's
getting cloned into new databases by CREATE DATABASE.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:40 ` Re: JDBC Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-06-10 23:05   ` Chuck Davis <cjgunzel@gmail.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Chuck Davis @ 2018-06-10 23:05 UTC (permalink / raw)
  To: ; +Cc: pgsql-jdbc

Yes, I've double checked.  There are no user space tables in the database.

On Sun, Jun 10, 2018 at 1:40 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Chuck Davis <cjgunzel@gmail.com> writes:
>> I created a new, empty database and I want to test whether a table
>> exists or not.
>
> Are you sure the DB is in fact empty?
>
>> The only thing I can think of is that the information_schema is
>> actually for the cluster.
>
> It is not.
>
>> I have other databases in the cluster that
>> do have an entities table.
>
> I'm betting that you created such a table in template1, so that it's
> getting cloned into new databases by CREATE DATABASE.
>
>                         regards, tom lane




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
@ 2018-06-10 20:44 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-06-10 23:09   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  1 sibling, 1 reply; 25+ messages in thread

From: David G. Johnston @ 2018-06-10 20:44 UTC (permalink / raw)
  To: Chuck Davis <cjgunzel@gmail.com>; +Cc: pgsql-jdbc

On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:

>
>         try {
>             result = stat.execute("select exists (select 1 from
> information_schema.tables where table_name = 'entities')");
>             System.out.println("the checkEntity returned a result of "
> + result);
>         } catch (SQLException ex) {
>             Logger.getLogger(ClientConstants.class.getName(
> )).log(Level.SEVERE,
> null, ex);
>             result = false;
>             return result;
>         }


Your query is putting "false" into cell (0,0) of a ResultSet.  You are
failing to even look at the resultset to see if it holds a true or false.

The query should never fail since you aren't using the table name directly
but are checking for it as a value in another table that always exists. The
inner query returns zero records when the table doesn't exist and the
EXISTS construct converts that to false.

David J.

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
@ 2018-06-10 23:09   ` Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 23:15     ` Re: JDBC Dave Cramer <pg@fastcrypt.com>
  2018-06-10 23:26     ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 25+ messages in thread

From: Chuck Davis @ 2018-06-10 23:09 UTC (permalink / raw)
  To: ; +Cc: pgsql-jdbc

If I try to return a ResultSet the class will not compile with the
message that boolean cannot be converted to a ResultSet.  And this is
in synch with the documentation that states the "exists" subquery will
return a boolean -- not a ResultSet.

There are a number of sites that indicate the statement is the way to
find out if a table exists.  Are the sites for an older version of PG?
 I'm running on 10.

Thanks.

On Sun, Jun 10, 2018 at 1:44 PM, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:
>>
>>
>>         try {
>>             result = stat.execute("select exists (select 1 from
>> information_schema.tables where table_name = 'entities')");
>>             System.out.println("the checkEntity returned a result of "
>> + result);
>>         } catch (SQLException ex) {
>>
>> Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
>> null, ex);
>>             result = false;
>>             return result;
>>         }
>
>
> Your query is putting "false" into cell (0,0) of a ResultSet.  You are
> failing to even look at the resultset to see if it holds a true or false.
>
> The query should never fail since you aren't using the table name directly
> but are checking for it as a value in another table that always exists. The
> inner query returns zero records when the table doesn't exist and the EXISTS
> construct converts that to false.
>
> David J.
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  2018-06-10 23:09   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
@ 2018-06-10 23:15     ` Dave Cramer <pg@fastcrypt.com>
  2018-06-10 23:21       ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  1 sibling, 1 reply; 25+ messages in thread

From: Dave Cramer @ 2018-06-10 23:15 UTC (permalink / raw)
  To: Chuck Davis <cjgunzel@gmail.com>; +Cc: pgsql-jdbc

On 10 June 2018 at 19:09, Chuck Davis <cjgunzel@gmail.com> wrote:

> If I try to return a ResultSet the class will not compile with the
> message that boolean cannot be converted to a ResultSet.  And this is
> in synch with the documentation that states the "exists" subquery will
> return a boolean -- not a ResultSet.
>
> There are a number of sites that indicate the statement is the way to
> find out if a table exists.  Are the sites for an older version of PG?
>  I'm running on 10.
>
> Thanks.
>
> On Sun, Jun 10, 2018 at 1:44 PM, David G. Johnston
> <david.g.johnston@gmail.com> wrote:
> > On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:
> >>
> >>
> >>         try {
> >>             result = stat.execute("select exists (select 1 from
> >> information_schema.tables where table_name = 'entities')");
> >>             System.out.println("the checkEntity returned a result of "
> >> + result);
> >>         } catch (SQLException ex) {
> >>
> >> Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
> >> null, ex);
> >>             result = false;
> >>             return result;
> >>         }
> >
> >
> > Your query is putting "false" into cell (0,0) of a ResultSet.  You are
> > failing to even look at the resultset to see if it holds a true or false.
> >
> > The query should never fail since you aren't using the table name
> directly
> > but are checking for it as a value in another table that always exists.
> The
> > inner query returns zero records when the table doesn't exist and the
> EXISTS
> > construct converts that to false.
> >
> > David J.
> >
>
>

idiomatic java suggests that you need to do

resultset rs = statement.query(your select statement)

if rs.next then
result = rs.getInt(1)

close result set and statement

return result == 1

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  2018-06-10 23:09   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 23:15     ` Re: JDBC Dave Cramer <pg@fastcrypt.com>
@ 2018-06-10 23:21       ` Chuck Davis <cjgunzel@gmail.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Chuck Davis @ 2018-06-10 23:21 UTC (permalink / raw)
  To: ; +Cc: pgsql-jdbc

If I query without the "exists" clause I get the PG exception that the
relation does not exist (which I guess tells me the table does not
exist) but I'd like a better way to test for existence than
exceptions.

On Sun, Jun 10, 2018 at 4:15 PM, Dave Cramer <pg@fastcrypt.com> wrote:
>
> On 10 June 2018 at 19:09, Chuck Davis <cjgunzel@gmail.com> wrote:
>>
>> If I try to return a ResultSet the class will not compile with the
>> message that boolean cannot be converted to a ResultSet.  And this is
>> in synch with the documentation that states the "exists" subquery will
>> return a boolean -- not a ResultSet.
>>
>> There are a number of sites that indicate the statement is the way to
>> find out if a table exists.  Are the sites for an older version of PG?
>>  I'm running on 10.
>>
>> Thanks.
>>
>> On Sun, Jun 10, 2018 at 1:44 PM, David G. Johnston
>> <david.g.johnston@gmail.com> wrote:
>> > On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:
>> >>
>> >>
>> >>         try {
>> >>             result = stat.execute("select exists (select 1 from
>> >> information_schema.tables where table_name = 'entities')");
>> >>             System.out.println("the checkEntity returned a result of "
>> >> + result);
>> >>         } catch (SQLException ex) {
>> >>
>> >> Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
>> >> null, ex);
>> >>             result = false;
>> >>             return result;
>> >>         }
>> >
>> >
>> > Your query is putting "false" into cell (0,0) of a ResultSet.  You are
>> > failing to even look at the resultset to see if it holds a true or
>> > false.
>> >
>> > The query should never fail since you aren't using the table name
>> > directly
>> > but are checking for it as a value in another table that always exists.
>> > The
>> > inner query returns zero records when the table doesn't exist and the
>> > EXISTS
>> > construct converts that to false.
>> >
>> > David J.
>> >
>>
>
>
> idiomatic java suggests that you need to do
>
> resultset rs = statement.query(your select statement)
>
> if rs.next then
> result = rs.getInt(1)
>
> close result set and statement
>
> return result == 1
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  2018-06-10 23:09   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
@ 2018-06-10 23:26     ` David G. Johnston <david.g.johnston@gmail.com>
  2018-06-11 01:33       ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  1 sibling, 1 reply; 25+ messages in thread

From: David G. Johnston @ 2018-06-10 23:26 UTC (permalink / raw)
  To: Chuck Davis <cjgunzel@gmail.com>; +Cc: pgsql-jdbc

On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:

> If I try to return a ResultSet the class will not compile with the
> message that boolean cannot be converted to a ResultSet.  And this is
> in synch with the documentation that states the "exists" subquery will
> return a boolean -- not a ResultSet.
>
>
The PostgreSQL documentation doesn't talk in terms JDBC, the Oracle JDBC
API specification covers that.

https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html

JDBC uses ResultSet to return the results of queries.


> There are a number of sites that indicate the statement is the way to
> find out if a table exists.  Are the sites for an older version of PG?
>  I'm running on 10.
>

This really has nothing to do with PostgreSQL specifically, you are failing
to use the JDBC API correctly.  In the short term you should probably just
use "executeQuery" instead of "execute" since you are in fact executing a
query that returns a ReaultSet (which is exactly what execute's true
boolean result is telling you).

David J.

^ permalink  raw  reply  [nested|flat] 25+ messages in thread

* Re: JDBC
  2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 20:44 ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
  2018-06-10 23:09   ` Re: JDBC Chuck Davis <cjgunzel@gmail.com>
  2018-06-10 23:26     ` Re: JDBC David G. Johnston <david.g.johnston@gmail.com>
@ 2018-06-11 01:33       ` Chuck Davis <cjgunzel@gmail.com>
  0 siblings, 0 replies; 25+ messages in thread

From: Chuck Davis @ 2018-06-11 01:33 UTC (permalink / raw)
  To: ; +Cc: pgsql-jdbc

Thanks David.  That got me going.  Getting the "false" value I expected.

On Sun, Jun 10, 2018 at 4:26 PM, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> On Sunday, June 10, 2018, Chuck Davis <cjgunzel@gmail.com> wrote:
>>
>> If I try to return a ResultSet the class will not compile with the
>> message that boolean cannot be converted to a ResultSet.  And this is
>> in synch with the documentation that states the "exists" subquery will
>> return a boolean -- not a ResultSet.
>>
>
> The PostgreSQL documentation doesn't talk in terms JDBC, the Oracle JDBC API
> specification covers that.
>
> https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html
>
> JDBC uses ResultSet to return the results of queries.
>
>>
>> There are a number of sites that indicate the statement is the way to
>> find out if a table exists.  Are the sites for an older version of PG?
>>  I'm running on 10.
>
>
> This really has nothing to do with PostgreSQL specifically, you are failing
> to use the JDBC API correctly.  In the short term you should probably just
> use "executeQuery" instead of "execute" since you are in fact executing a
> query that returns a ReaultSet (which is exactly what execute's true boolean
> result is telling you).
>
> David J.
>




^ permalink  raw  reply  [nested|flat] 25+ messages in thread


end of thread, other threads:[~2018-06-11 01:33 UTC | newest]

Thread overview: 25+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-16 23:34 JDBC Michael Welter <mike@introspect.com>
2002-02-17 00:56 ` Barry Lind <barry@xythos.com>
2002-12-11 21:40 JDBC Alvaro Escobar <escobar_alvaro@hotmail.com>
2003-01-14 12:26 JDBC Marcelo Pereira <gandalf@sum.desktop.com.br>
2003-01-14 18:50 ` Jeffrey Melloy <jmelloy@visualdistortion.org>
2003-01-15 13:08   ` Marcelo Pereira <gandalf@sum.desktop.com.br>
2003-01-15 12:55     ` Dave Cramer <Dave@micro-automation.net>
2003-01-15 14:17       ` Marcelo Pereira <gandalf@sum.desktop.com.br>
2003-03-20 11:37 JDBC Maicol <maicol@wiz.com.br>
2003-04-08 17:44 JDBC Sohail A. Khan <Sohail.A.Khan@student.shu.ac.uk>
2003-04-08 18:33 ` Dave Cramer <Dave@micro-automation.net>
2003-08-04 17:55 JDBC Lufkin, Brad <brad.lufkin@ngc.com>
2003-08-04 21:05 ` Nick Fankhauser <nickf@ontko.com>
2003-08-04 21:06 ` Kris Jurka <books@ejurka.com>
2004-08-24 14:50 JDBC Hanna Tapani <tapani@kth.se>
2004-08-24 15:16 ` Kris Jurka <books@ejurka.com>
2018-06-10 20:24 Re: JDBC Chuck Davis <cjgunzel@gmail.com>
2018-06-10 20:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-06-10 23:05   ` Chuck Davis <cjgunzel@gmail.com>
2018-06-10 20:44 ` David G. Johnston <david.g.johnston@gmail.com>
2018-06-10 23:09   ` Chuck Davis <cjgunzel@gmail.com>
2018-06-10 23:15     ` Dave Cramer <pg@fastcrypt.com>
2018-06-10 23:21       ` Chuck Davis <cjgunzel@gmail.com>
2018-06-10 23:26     ` David G. Johnston <david.g.johnston@gmail.com>
2018-06-11 01:33       ` Chuck Davis <cjgunzel@gmail.com>

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