Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JDBC PostgreSQL

11 views
Skip to first unread message

Javi Roman

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
Hello:
I am making my first example of connection to a DB (postgreSQL) by JDBC
and is being frustante.
I do not have much idea of Java and I do not interpret the messages of
error of the compiler well.
I have the following code:

import java.sql.*;

public class Consulta{

public static void main(String agrs[])
{
try{
Class.forName("jdbc6.5-1.2.Driver");
Connection conexion =
DriverManager.getConnection("jdbc:jdbc6.5-1.2//localhost:5432/clientes");
Statement orden = conexion.createStatement();
ResultSet resultado = orden.executeQuery("SELECT
* FROM pedidos");
resultado.next();
System.out.println(resultado.getString(2));

resultado.close();
orden.close();
conexion.close();

} catch (ClassNotFoundException e){
System.out.println("Controlador no
encontrado: " + e);

} catch (SQLException e){
System.out.println("Excepcion SQL: " +
e);
}
}
}

The compiler does not give any error but when sending the interpreter
java I obtain the following thing:

# java Consulta.class
java.lang.NoClassDefFoundError: Consulta/class
at java.lang.Throwable.<init>(Throwable.java:38)
at java.lang.Error.<init>(Error.java:21)
at java.lang.LinkageError.<init>(LinkageError.java:21)
at
java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:21)

¿Why?
--
----------------
ESware Linux
www.esware.com
----------------

Alexander Schmid

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
Javi Roman wrote:

Maybe I'm missing the point, but you have to start your application
with "java Consulta" (without the .class). Hope that helps...

Ciao Alex


Travis Bauer

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
Javi Roman wrote:

One problem is the name of the driver. I believe it should be
postgresql.Driver. Put the driver's jar file in your classpath, and refer
to it by this other name. Look in the JDBC examples for the exact name.

You probably want to consider upgrading to the latest version of
postgreslq. It has a lot of new features and is a significant advance over
what you have. In that version, you refer to the JDBC driver as
org.postgresql.Driver.

----------------------------------------------------------------
Travis Bauer | CS Grad Student | IU |www.cs.indiana.edu/~trbauer
----------------------------------------------------------------

> Hello:

> Class.forName("jdbc6.5-1.2.Driver");
> java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:21)


Tim Webster

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
in article 39A3E755...@indiana.edu, Travis Bauer at
trb...@indiana.edu wrote on 8/23/00 10:01 AM:

> Javi Roman wrote:
>
> One problem is the name of the driver. I believe it should be
> postgresql.Driver. Put the driver's jar file in your classpath, and refer
> to it by this other name. Look in the JDBC examples for the exact name.
>

Agreed. also, the protocol string should look like

jdbc:postgresql://localhost:5432/clientes

rather than

> jdbc:jdbc6.5-1.2//localhost:5432/clientes

Timo Rantalaiho

unread,
Aug 24, 2000, 3:00:00 AM8/24/00
to
In <39A3E64C...@esware.com> Javi Roman <ja...@esware.com> writes:

> Class.forName("jdbc6.5-1.2.Driver");

Should be "postgresql.Driver", or "org.postgresql.Driver" for
version 7.0. You also need to have jdbc6.5-1.2.jar in your
class path.

>DriverManager.getConnection("jdbc:jdbc6.5-1.2//localhost:5432/clientes");

Should be "jdbc:postgresql://localhost:5432/clientes"
(though I think that ":5432" can be left out because it is the
default port for PgSQL).

># java Consulta.class

Should be "java Consulta" without ".class";

>java.lang.NoClassDefFoundError: Consulta/class

So it's looking for a class named "class" in a package named
"Consulta".

--
Timo.Ra...@iki.fi
Help keep Usenet clean: <URL: http://www.hut.fi/u/jkorpela/usenet/dont.html >

Muhammad Amin

unread,
Aug 24, 2000, 3:00:00 AM8/24/00
to
Check for the correct name of the driver, which should be
postgresql.Driver and the the database URL:
jdbc:postgres://database-host-name:port/database-name

--Lamine.


On Wed, 23 Aug 2000 10:01:41 -0500, Travis Bauer <trb...@indiana.edu>
wrote:

>Javi Roman wrote:
>
>One problem is the name of the driver. I believe it should be
>postgresql.Driver. Put the driver's jar file in your classpath, and refer
>to it by this other name. Look in the JDBC examples for the exact name.
>

0 new messages