• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classpath and jdbc

 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your first customer win a toaster? Oh yippee, please send it to me at pauline@javaranch.com.
I've just installed mySQL and Connector/J. I was able to play with mySQL successfully, but have had less luck accessing the db via jdbc.
I expanded (with Stuffit Expander) mysql-connector-java-3.0.8-stable.zip at the root of the hard disk. There is now a folder called mysql-connector-java-#491A3Folder.
The jar file, mysql-connector-java-3.0.8-stable-bin.jar, is located one folder down at /mysql-connector-java-#491A3Folder/mysql-connector-java-3.0.8-stable/mysql-connector-java-3.0.8-stable-bin.jar
The java file I'm testing with looks like this:

With the jar in the classpath, I can compile Test.java ok, but running it gives me a class not found exception with the Driver class:
could not load JDBC driver: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I suspect some kind of classpath problem...

Thanks,
Pauline
[ June 21, 2003: Message edited by: Pauline McNamara ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might try putting the jar file in the java extensions folder, located in /Library/Java/Extensions I believe.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still working my way through the intricities of jdbc, and even though I have the driver in my $PATH, thusfar the only way I've gotten my programs to work is by java -classpath </usr/local/lib/mysql/mysql-connector...etc...> <progName>. It's annoying , however until I find a simpler means, it works.
Regards, Michael
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Michael... yeah PATH won't do anything for you. That's the path that the shell uses to look for command programs; Java ignores it.
Java will look on the path defined by CLASSPATH, as well as in well-known folders (as Rob suggested) for class files -- in addition to those you specify on the command line.
hth,
bear
 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Presently I'm experimenting with tcsh. I have set the pathes in my .tcshrc file. Shouldn't this make the pathes available to Java?
Regardless, I'll try what Rob suggested since I'm getting tired of typing out the driver...
thanks, Michael

Originally posted by Bear Bibeault:
Hey Michael... yeah PATH won't do anything for you. That's the path that the shell uses to look for command programs; Java ignores it.
Java will look on the path defined by CLASSPATH, as well as in well-known folders (as Rob suggested) for class files -- in addition to those you specify on the command line.
hth,
bear


[ June 22, 2003: Message edited by: michael bradly ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how did you set the classpath in your login script? Remember PATH isn't the right environment variable to use...
bear
 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done a bit of research on it and understand what the difference is now..
I've made a few modifications... now back to figuring out tomcat

Originally posted by Bear Bibeault:
But how did you set the classpath in your login script? Remember PATH isn't the right environment variable to use...
bear

 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Ross:
You might try putting the jar file in the java extensions folder, located in /Library/Java/Extensions I believe.


Thanks Rob, this seemed to help. (Though I wonder why just having it in the classpath didn't work.) That is, I'm getting a different type of error now.
Now there seems to be a question of permissions...
java.sql.SQLException: General error, message from server: "Access denied for user: '@localhost' to database 'soup'
I'm thinking that this is where a GRANT bla bla comes in, but am confused about the user '@localhost' - no user name there?

Thanks in advance,
Pauline
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For whatever it's worth, I figured out the access denied problem, it's not really mac specific.
I had set permissions on the database, but didn't specify a userid in the DriverManager.getConnection() call. Used getConnection( url , userid, userpassword ) and got in.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Going back to my original problem with the class not found exception...
Is there any reason that putting the connector .jar file in the classpath wouldn't work whereas putting it in /Library/Java/Extensions does?
Any advantages one way or the other?
Should I be concerned, or just stick with what worked?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The extensions folder is a well-known place that all java JVMs look for libraries; this folder is actually always implicitly in your classpath, that's why this works. Different types of libraries might warrant being placed here, but keep in mind they're globally available to anyone using that JVM; so if you have different versions of the libs or you want to restrict access to a specific user, putting them in that folder might not be the best solution.
You didn't include your actual script to launch your program; can you do that so I can check it? Also, can you diagram out your folder structure for me, like

etc? Also, I don't know if it's an issue but those directory names sure look funky to me. What's with the -#491A3 in the name?
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob.
Yeah, Stuffit Expander had chopped off part of the name, too, I'll check what it's called when it gets unzipped from Windows at work, uh, Monday. That's also when I'll be able to get back to you with that other stuff, the weekend is quickly approaching and I'm giving my tibook a couple days off.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a note: When Stuffit Expander annoys me (often) I resort to using the java jar command to manipulate zip files.
hth,
bear
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooh, that's definitely a weird folder name. I'll have to try again using jar (thanks Bear) or see if ZipIt can handle it more cleanly...
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was it, got it working by just unzipping with jar and replacing that goofy folder. Thanks.

Next question..
When using jar I ended up waiting longer than necessary, I think, because it didn't give me the command line again; I did a ctrl + . to stop it, then noticed the folder had been created (it might have already been there, don't know). Is this the normal procedure?
Oh, yeah, and when do I get my toaster?
[ June 30, 2003: Message edited by: Pauline McNamara ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, no I've never had a problem with the jar command not terminating. Does this happen every time you use it?
bear
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, er, that is, the one and only time I used it. I'll try to reproduce it.
...
Just used it for a different zip file, and it didn't terminate and didn't unzip either...
Is my syntax off?
jar -x path/to/file.zip
...
Back again, after cd'ing to the directory the file is in and using
jar xf file.zip
This terminated right away, pulled out the files that were in the .zip, but didn't create a folder - the files showed up in the same directory as the zip file.
So if I create the folder myself and do the jar from there I'm all set (almost as good as Windows yippee
[ July 01, 2003: Message edited by: Pauline McNamara ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes, as you found out, if you leave off the 'f', the jar command (like many other unix commands) will wait for you to enter the input at the console.
As for not creating the folder hierarchy, that's not a problem I've had. If you use 'jar tf myfile.zip' it will show you what is in the zip file so you can check if the folders are as you expect within the file.
Using 'jar xvf myfile.zip' to unpack will show a list of folders/files as it is unpacking.
hth,
bear
[ July 01, 2003: Message edited by: Bear Bibeault ]
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, Bear.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic