Обсуждение: Trouble With JDBC

Поиск
Список
Период
Сортировка

Trouble With JDBC

От
Corey Mosher
Дата:
Hi,

  I am trying to test out the postgres-JDBC driver.  I have a
file called sample.java.  It compiles fine, but when I run it
I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: sample/java

This is what my classpath is set to:

export CLASSPATH=.:/usr/local/java_pkgs/jdk1.1.8/lib/postgresql.jar:$CLASSPATH

Anyone have any idea as to what is wrong?  It looks as if it can't find the
sample.class file, but it does exist in the current directory.


Thanks

Corey Mosher

-----------------------------
Hub.Org Networking Services
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@hub.org
Phone: (902) 542-3657
-----------------------------
PostgreSQL, Inc.
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@pgsql.com
Phone: (902) 542-0713
-----------------------------
Fax:   (902) 542-5386


Re: Trouble With JDBC

От
Peter T Mount
Дата:
Quoting Corey Mosher <corey@pgsql.com>:

> Hi,
>
>   I am trying to test out the postgres-JDBC driver.  I have a
> file called sample.java.  It compiles fine, but when I run it
> I get the following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: sample/java
>
> This is what my classpath is set to:
>
> export
> CLASSPATH=.:/usr/local/java_pkgs/jdk1.1.8/lib/postgresql.jar:$CLASSPATH
>
> Anyone have any idea as to what is wrong?  It looks as if it can't find
> the
> sample.class file, but it does exist in the current directory.

Erm, you are not including .class in the java line are you?

eg: java sample.class?

If so, drop the .class. It's looking for a file sample/class.class not
sample.class

;-)

Peter


--
Peter Mount peter@retep.org.uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/

Re: Trouble With JDBC

От
Michael Stephenson
Дата:
> > Exception in thread "main" java.lang.NoClassDefFoundError: sample/java
[snip]
> Erm, you are not including .class in the java line are you?
>
> eg: java sample.class?

*cough*
You mean sample.java

Answer is the same though, just use:

java sample
</pointless reiteration>

Michael Stephenson      mstephenson@openworld.co.uk
Developer   -    Web Applications    -   Open World
Tel: +44 1225 444 950         Fax: +44 1225 336 738


Re: Trouble With JDBC

От
Bob Kline
Дата:
On Fri, 16 Feb 2001, Corey Mosher wrote:

> Hi,
>
>   I am trying to test out the postgres-JDBC driver.  I have a
> file called sample.java.  It compiles fine, but when I run it
> I get the following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: sample/java
>
> This is what my classpath is set to:
>
> export CLASSPATH=.:/usr/local/java_pkgs/jdk1.1.8/lib/postgresql.jar:$CLASSPATH
>
> Anyone have any idea as to what is wrong?  It looks as if it can't
> find the sample.class file, but it does exist in the current
> directory.

You might want to start with an introductory book on Java.  It looks as
if you've included the source code filename extension in your
command-line invocation of the program.  Drop the ".java" and see what
happens.

--
Bob Kline
mailto:bkline@rksystems.com
http://www.rksystems.com


Re: Trouble With JDBC

От
Corey Mosher
Дата:
No, to run the program I am using:
java sample

To compile it I am using:
javac sample.java

I have had other simple programs running (the usual hello world apps)
and they seem to work fine.  Just this one for some reason gets the
error.

Corey

On Fri, 16 Feb 2001, Bob Kline wrote:

> On Fri, 16 Feb 2001, Corey Mosher wrote:
>
> > Hi,
> >
> >   I am trying to test out the postgres-JDBC driver.  I have a
> > file called sample.java.  It compiles fine, but when I run it
> > I get the following error:
> >
> > Exception in thread "main" java.lang.NoClassDefFoundError: sample/java
> >
> > This is what my classpath is set to:
> >
> > export CLASSPATH=.:/usr/local/java_pkgs/jdk1.1.8/lib/postgresql.jar:$CLASSPATH
> >
> > Anyone have any idea as to what is wrong?  It looks as if it can't
> > find the sample.class file, but it does exist in the current
> > directory.
>
> You might want to start with an introductory book on Java.  It looks as
> if you've included the source code filename extension in your
> command-line invocation of the program.  Drop the ".java" and see what
> happens.
>
>

Corey Mosher

-----------------------------
Hub.Org Networking Services
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@hub.org
Phone: (902) 542-3657
-----------------------------
PostgreSQL, Inc.
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@pgsql.com
Phone: (902) 542-0713
-----------------------------
Fax:   (902) 542-5386


Re: Trouble With JDBC

От
Bob Kline
Дата:
On Fri, 16 Feb 2001, Corey Mosher wrote:

> No, to run the program I am using:
> java sample
>
> To compile it I am using:
> javac sample.java
>
> I have had other simple programs running (the usual hello world
> apps) and they seem to work fine.  Just this one for some reason
> gets the error.

Let's take a look at the source, then, to see if we can spot the
problem.

--
Bob Kline
mailto:bkline@rksystems.com
http://www.rksystems.com


Re: Trouble With JDBC

От
Corey Mosher
Дата:
The source code is from the book:
PostgreSQL: Introduction And Concepts

Located at: http://www.postgresql.org/docs/aw_pgsql_book/node192.html

I wanted to use some code that I knew worked to overcome problems
like I am having.

Corey


On Fri, 16 Feb 2001, Bob Kline wrote:

> On Fri, 16 Feb 2001, Corey Mosher wrote:
>
> > No, to run the program I am using:
> > java sample
> >
> > To compile it I am using:
> > javac sample.java
> >
> > I have had other simple programs running (the usual hello world
> > apps) and they seem to work fine.  Just this one for some reason
> > gets the error.
>
> Let's take a look at the source, then, to see if we can spot the
> problem.
>
>

Corey Mosher

-----------------------------
Hub.Org Networking Services
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@hub.org
Phone: (902) 542-3657
-----------------------------
PostgreSQL, Inc.
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@pgsql.com
Phone: (902) 542-0713
-----------------------------
Fax:   (902) 542-5386


Re: Trouble With JDBC

От
Michael Stephenson
Дата:
> Located at: http://www.postgresql.org/docs/aw_pgsql_book/node192.html
>
> I wanted to use some code that I knew worked to overcome problems
> like I am having.

There is nothing wrong with the code, to run it you'll need lines similar
to:

mstephen@sokoki:~$ export CLASSPATH=/home/mstephen/local/postgresql.jar:.
mstephen@sokoki:~$ javac sample.java
mstephen@sokoki:~$ java sample

If these simple steps are not working for you then something very strange
is going on.

If the code is compiling then it is not a postgres or jdbc problem, but a
problem with your VM, and I don't think this is the best place to find a
solution.

If it isn't compiling then get a new (as in, not broken, as opposed to
recent, there is no code in sample which should not work in any version
of the jdbc driver) postgres jar file and try again.

Michael Stephenson      mstephenson@openworld.co.uk
Developer   -    Web Applications    -   Open World
Tel: +44 1225 444 950         Fax: +44 1225 336 738


Re: Trouble With JDBC

От
Bob Kline
Дата:
I'm not saying I doubt what you're telling me about how you're trying to
run the program, but you might want to try again.  Watch this:

$ javac sample.java
$ java sample
Enter a state code:  VA
Virginia
$ java sample.java
Exception in thread "main" java.lang.NoClassDefFoundError: sample/java

Look familiar?

Good luck,
Bob

On Fri, 16 Feb 2001, Corey Mosher wrote:

> The source code is from the book:
> PostgreSQL: Introduction And Concepts
>
> Located at: http://www.postgresql.org/docs/aw_pgsql_book/node192.html
>
> I wanted to use some code that I knew worked to overcome problems
> like I am having.
>
> Corey
>
>
> On Fri, 16 Feb 2001, Bob Kline wrote:
>
> > On Fri, 16 Feb 2001, Corey Mosher wrote:
> >
> > > No, to run the program I am using:
> > > java sample
> > >
> > > To compile it I am using:
> > > javac sample.java
> > >
> > > I have had other simple programs running (the usual hello world
> > > apps) and they seem to work fine.  Just this one for some reason
> > > gets the error.
> >
> > Let's take a look at the source, then, to see if we can spot the
> > problem.
> >
> >
>
> Corey Mosher
>
> -----------------------------
> Hub.Org Networking Services
> 251 Main St.
> Wolfville, NS
> Canada
> B0P 1X0
> Email: corey@hub.org
> Phone: (902) 542-3657
> -----------------------------
> PostgreSQL, Inc.
> 251 Main St.
> Wolfville, NS
> Canada
> B0P 1X0
> Email: corey@pgsql.com
> Phone: (902) 542-0713
> -----------------------------
> Fax:   (902) 542-5386
>

--
Bob Kline
mailto:bkline@rksystems.com
http://www.rksystems.com


Re: Trouble With JDBC

От
Corey Mosher
Дата:
So there has got to be something wrong with the way I'm setting my classpath
in that when I type java sample it is trying to use sample.java instead
of sample.class.

I'll play around with the classpath and see what I come up with.

Thanks Bob, I appreciate it.

Corey

On Fri, 16 Feb 2001, Bob Kline wrote:

> I'm not saying I doubt what you're telling me about how you're trying to
> run the program, but you might want to try again.  Watch this:
>
> $ javac sample.java
> $ java sample
> Enter a state code:  VA
> Virginia
> $ java sample.java
> Exception in thread "main" java.lang.NoClassDefFoundError: sample/java
>
> Look familiar?
>
> Good luck,
> Bob
>
> On Fri, 16 Feb 2001, Corey Mosher wrote:
>
> > The source code is from the book:
> > PostgreSQL: Introduction And Concepts
> >
> > Located at: http://www.postgresql.org/docs/aw_pgsql_book/node192.html
> >
> > I wanted to use some code that I knew worked to overcome problems
> > like I am having.
> >
> > Corey
> >
> >
> > On Fri, 16 Feb 2001, Bob Kline wrote:
> >
> > > On Fri, 16 Feb 2001, Corey Mosher wrote:
> > >
> > > > No, to run the program I am using:
> > > > java sample
> > > >
> > > > To compile it I am using:
> > > > javac sample.java
> > > >
> > > > I have had other simple programs running (the usual hello world
> > > > apps) and they seem to work fine.  Just this one for some reason
> > > > gets the error.
> > >
> > > Let's take a look at the source, then, to see if we can spot the
> > > problem.
> > >
> > >
> >
> > Corey Mosher
> >
> > -----------------------------
> > Hub.Org Networking Services
> > 251 Main St.
> > Wolfville, NS
> > Canada
> > B0P 1X0
> > Email: corey@hub.org
> > Phone: (902) 542-3657
> > -----------------------------
> > PostgreSQL, Inc.
> > 251 Main St.
> > Wolfville, NS
> > Canada
> > B0P 1X0
> > Email: corey@pgsql.com
> > Phone: (902) 542-0713
> > -----------------------------
> > Fax:   (902) 542-5386
> >
>
>

Corey Mosher

-----------------------------
Hub.Org Networking Services
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@hub.org
Phone: (902) 542-3657
-----------------------------
PostgreSQL, Inc.
251 Main St.
Wolfville, NS
Canada
B0P 1X0
Email: corey@pgsql.com
Phone: (902) 542-0713
-----------------------------
Fax:   (902) 542-5386