Thread: PostgreSQL-JDBC correct URL

PostgreSQL-JDBC correct URL

From
Haroldo Stenger
Date:
Hello nice people,

/* I'm a GeneXus programmer (www.genexus.com), a RAD tool. They support natively
Oracle, Informix, DB2 & MS SQL Server. I'm taking steps to use and encourage use
by others, of PostgreSQL, which I thing is the most amazing DBMS out there these
days. Java is the language I chose to generate my future applications using
GeneXus.
*/

GeneXus asks me for the driver name, and for the URL of the JDBC driver. Then,
when trying to connect to the database, a Java java.lang.ClassNotFoundException
appears. I seem to be failing to tell the right name of the driver. I tried
gnu.postgres95.PGDriver, and others like this. And for the URL, I used
jdbc:postgres95:template1?user=haroldo&password=haroldo

With this template:
jdbc:driver://host:port/database?option=value&user=userid&password=password  I
wonder what 'driver' must be, if either postgres95 or postgresql or postgreSQL.

I'm using the Postgresql 6.5 JDK1.1.x JDBC driver. Does it use the same URL
format as earlier versions, i.e. postgres95 versions?

I'd like to thank in advance to Peter Mount, o whoever answers this.

--

Saludos,
Haroldo.

------------------------------
"Y con esto me despido
Sin expresar hasta cuando.
Siempre corta por lo blando
El que busca lo siguro;
Mas yo corto por lo duro,
Y ansí he de seguir cortando."

José Hernández - Martín Fierro
------------------------------

Re: PostgreSQL-JDBC correct URL

From
Silvio Macedo
Date:
This is what I use for JDBC:

(There are other ways. Read the jdbc documentation OR the source
directly. There are MANY examples, and the docs are more than enough.

Did you read them ?!

)

final public static String DBURL =
"jdbc:postgresql://host.domain:5432/dbname";

final public static String driverName =
"postgresql.Driver";

            // The postgresql.jar must be in classpath
Class.forName(driverName);

java.sql.Connection connection =
DriverManager.getConnection(DBURL,username,password);

...

Cheers, Silvio


On Mon, 10 Apr 2000, Haroldo Stenger wrote:

> Hello nice people,
>
> /* I'm a GeneXus programmer (www.genexus.com), a RAD tool. They support natively
> Oracle, Informix, DB2 & MS SQL Server. I'm taking steps to use and encourage use
> by others, of PostgreSQL, which I thing is the most amazing DBMS out there these
> days. Java is the language I chose to generate my future applications using
> GeneXus.
> */
>
> GeneXus asks me for the driver name, and for the URL of the JDBC driver. Then,
> when trying to connect to the database, a Java java.lang.ClassNotFoundException
> appears. I seem to be failing to tell the right name of the driver. I tried
> gnu.postgres95.PGDriver, and others like this. And for the URL, I used
> jdbc:postgres95:template1?user=haroldo&password=haroldo
>
> With this template:
> jdbc:driver://host:port/database?option=value&user=userid&password=password  I
> wonder what 'driver' must be, if either postgres95 or postgresql or postgreSQL.
>
> I'm using the Postgresql 6.5 JDK1.1.x JDBC driver. Does it use the same URL
> format as earlier versions, i.e. postgres95 versions?
>
> I'd like to thank in advance to Peter Mount, o whoever answers this.
>
>

--
``````````` Silvio Emanuel Nunes Barbosa de Macedo (PhD Std) '''''''''''''
smacedo@ic.ac.uk                                         smacedo@inescn.pt
Intelligent and Interactive Systems                Telecom. and Multimedia
Imperial College, University of London                         INESC Porto
Exhibition Road,                                       Pc da Republica, 93
London SW7 2AZ, England                            4050-497 Porto Portugal
Tel:+44 171 5946323                                    Tel:+351 22 2094220



Re: PostgreSQL-JDBC correct URL

From
Haroldo Stenger
Date:
Now I need help in finding:

    - A list of the errors of the backend, _WITH_ the numbers, not only the
texts.

    - I need to track the queries that the backend receives, so that I can
see what GeneXus is sending to PostgreSQL.

I coudn't find this info in the doc, either. Any Ideas? Thanks in
advance.


Silvio Macedo wrote:
>
> This is what I use for JDBC:
>
> (There are other ways. Read the jdbc documentation OR the source
> directly. There are MANY examples, and the docs are more than enough.
>
> Did you read them ?!

No, because the driver has no documentation, or I couldn't find it.

>
> )
>
> final public static String DBURL =
> "jdbc:postgresql://host.domain:5432/dbname";
>
> final public static String driverName =
> "postgresql.Driver";

This worked fine. Thankyou.

>
>                         // The postgresql.jar must be in classpath
> Class.forName(driverName);
>
> java.sql.Connection connection =
> DriverManager.getConnection(DBURL,username,password);
>
> ...
>
> Cheers, Silvio
>
> On Mon, 10 Apr 2000, Haroldo Stenger wrote:
>
> > Hello nice people,
> >
> > /* I'm a GeneXus programmer (www.genexus.com), a RAD tool. They support natively
> > Oracle, Informix, DB2 & MS SQL Server. I'm taking steps to use and encourage use
> > by others, of PostgreSQL, which I thing is the most amazing DBMS out there these
> > days. Java is the language I chose to generate my future applications using
> > GeneXus.
> > */
> >
> > GeneXus asks me for the driver name, and for the URL of the JDBC driver. Then,
> > when trying to connect to the database, a Java java.lang.ClassNotFoundException
> > appears. I seem to be failing to tell the right name of the driver. I tried
> > gnu.postgres95.PGDriver, and others like this. And for the URL, I used
> > jdbc:postgres95:template1?user=haroldo&password=haroldo
> >
> > With this template:
> > jdbc:driver://host:port/database?option=value&user=userid&password=password  I
> > wonder what 'driver' must be, if either postgres95 or postgresql or postgreSQL.
> >
> > I'm using the Postgresql 6.5 JDK1.1.x JDBC driver. Does it use the same URL
> > format as earlier versions, i.e. postgres95 versions?
> >
> > I'd like to thank in advance to Peter Mount, o whoever answers this.
> >
> >
>
> --
> ``````````` Silvio Emanuel Nunes Barbosa de Macedo (PhD Std) '''''''''''''
> smacedo@ic.ac.uk                                         smacedo@inescn.pt
> Intelligent and Interactive Systems                Telecom. and Multimedia
> Imperial College, University of London                         INESC Porto
> Exhibition Road,                                       Pc da Republica, 93
> London SW7 2AZ, England                            4050-497 Porto Portugal
> Tel:+44 171 5946323                                    Tel:+351 22 2094220

Re: PostgreSQL-JDBC correct URL

From
Silvio Macedo
Date:
On Wed, 12 Apr 2000, Haroldo Stenger wrote:
> Now I need help in finding:

Hello to you too. :)


>     - I need to track the queries that the backend receives, so that I can
> see what GeneXus is sending to PostgreSQL.

http://www.postgresql.org/docs/admin/pg-options.htm


>
>     - A list of the errors of the backend, _WITH_ the numbers, not only the
> texts.

Try to print the SQLException and SQLWarning descriptions
using e.getMessage()  and e.getSQLState()

This and the tip above should give you enough info.

I don't know what error codes you are talking - if you mean the ones
returned by getErrorCode() at the JDBC level, getMessage will help you for
sure. If you mean others, at backend level (?), I don't know.

Also, I usually have my own software printing the SQL queries during debug
time (before they are sent, if they are not PreparedStatement s)

>
> I coudn't find this info in the doc, either. Any Ideas? Thanks in
> advance.
> > Did you read them ?!
> No, because the driver has no documentation, or I couldn't find it.

http://www.postgresql.org/docs/programmer/jdbc.htm

or better, one of the mirrors .


Good Work!


--
``````````` Silvio Emanuel Nunes Barbosa de Macedo (PhD Std) '''''''''''''
smacedo@ic.ac.uk                                         smacedo@inescn.pt
Intelligent and Interactive Systems                Telecom. and Multimedia
Imperial College, University of London                         INESC Porto
Exhibition Road,                                       Pc da Republica, 93
London SW7 2AZ, England                            4050-497 Porto Portugal
Tel:+44 171 5946323                                    Tel:+351 22 2094220


Re: PostgreSQL-JDBC correct URL

From
Haroldo Stenger
Date:
Hello Silvio,

I want to thank you especially for having helped me. I overlooked a lot
of doc, especially the programmer's guide.

The point on the error numbers is because GeneXus generated java code,
does things that give errors: it locks tables that don't exists for
example. It also drops tables that don' exist. It is when they connect
to Informix, which is the dbms that I have GeneXus configure for (it dos
not support PostgreSQl yet). Then, they catch up the error message BY
NUMBER. They sent the java source to me, where there are the
correspondin numbers to each error message)

Example:

        public boolean EndOfFile(int GXSQLCODE)
        {
                return  (       GXSQLCODE == 100                /* End
of file */
                                );
        }
        public boolean DuplicateKeyValue(int GXSQLCODE)
        {
                return  (       GXSQLCODE == -239 ||    /* Could not
insert row. Duplicate value in unique index column */
                                        GXSQLCODE == -268
/* Unique constraint violated */
                                );

        }
        public boolean ObjectLocked(int GXSQLCODE)
        {
                return  (       GXSQLCODE == -243  ||   /* Could not
position within a table */
                                        GXSQLCODE == -244  ||   /* Could
not do a physical-order read to fetch next row */
                                        GXSQLCODE == -245
/* Could not position within a file via an index */
                                );
        }
        public boolean ObjectNotFound(int GXSQLCODE)
        {
                return  (       GXSQLCODE == -206  ||   /* The specified
table is not in the database */
                                        GXSQLCODE == -319  ||   /* Index
does not exist in ISAM file */
                                        GXSQLCODE == -623
/* Unable to find constraint */
                                );



So, I'm supposed to substitute the numbers with the PostgreSQL numbers.
I think the numbers exist at a JDBC level, not at a backend level.

This is one approach. At the same time, by looking to the SQL statements
log, I observed that when within a begin/commit work, an inexistent
table is locked, the error leaves the backend in an aborted state, until
the commit. Question: Does this mean that GeneXus approach of doing
erroneous things (such as locking or dropping inexistent tables within a
transaction), and then catching the errors at a JDBC level won't work
with PostgreSQL? Or is there a way of telling the backend that we want
it to ignore the offending statement?

Please be patient with me, as I'm fairly new to PostgreSQL, and new to
Java.

Cheers!


Silvio Macedo wrote:
>
> On Wed, 12 Apr 2000, Haroldo Stenger wrote:
> > Now I need help in finding:
>
> Hello to you too. :)
>
> >       - I need to track the queries that the backend receives, so that I can
> > see what GeneXus is sending to PostgreSQL.
>
> http://www.postgresql.org/docs/admin/pg-options.htm
>
> >
> >       - A list of the errors of the backend, _WITH_ the numbers, not only the
> > texts.
>
> Try to print the SQLException and SQLWarning descriptions
> using e.getMessage()  and e.getSQLState()
>
> This and the tip above should give you enough info.
>
> I don't know what error codes you are talking - if you mean the ones
> returned by getErrorCode() at the JDBC level, getMessage will help you for
> sure. If you mean others, at backend level (?), I don't know.
>
> Also, I usually have my own software printing the SQL queries during debug
> time (before they are sent, if they are not PreparedStatement s)
>
> >
> > I coudn't find this info in the doc, either. Any Ideas? Thanks in
> > advance.
> > > Did you read them ?!
> > No, because the driver has no documentation, or I couldn't find it.
>
> http://www.postgresql.org/docs/programmer/jdbc.htm
>
> or better, one of the mirrors .
>
> Good Work!
>
> --
> ``````````` Silvio Emanuel Nunes Barbosa de Macedo (PhD Std) '''''''''''''
> smacedo@ic.ac.uk                                         smacedo@inescn.pt
> Intelligent and Interactive Systems                Telecom. and Multimedia
> Imperial College, University of London                         INESC Porto
> Exhibition Road,                                       Pc da Republica, 93
> London SW7 2AZ, England                            4050-497 Porto Portugal
> Tel:+44 171 5946323                                    Tel:+351 22 2094220