Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm setting up a simple JDBC connection to my working MySQL database on my server. I'm using the Connector-J provided by MySQL. According to their documentation, I'm suppose to create the CLASSPATH variable to point to the directory where the mysql-connector-java-5.0.8-bin.jar is located. I used export set CLASSPATH=/path/mysql-connector-java-5.0.8-bin.jar:$CLASSPATH. When I type echo $CLASSPATH to see if it exists, everything seems fine. But then when I open a new terminal and type echo $CLASSPATH it's no longer there. I think this is the main reason why my Java server won't connect to the JDBC, because it isn't saving the CLASSPATH variable I set.

Anyone got suggestions or fixes on how to set up JDBC in the first place?

share|improve this question

When you use 'export' to set the $CLASSPATH it will only be set for that terminal session. What you want to do is add a line

export CLASSPATH=/path/mysql-connector-java-5.0.8-bin.jar:$CLASSPATH

to the ~/.bash_profile of the user that will be needing to reference the variable. This way it will be exported each time a new session is started and you do not need to export it manually each time.

share|improve this answer
Yea, that worked out. However, it didn't fix my original problem, lol, still can't get JDBC to work properly. The thing is that my original server had a hard drive failure which is why I'm setting up this new one. I know the Java server file I'm running works because it worked on my old server that had JDBC set up and working just fine. I just don't know why this JDBC isn't working as easily on this machine. – AeroDroid Jan 19 '11 at 2:48
In your original post you said it needs to be set to the directory, not the file itself. Try setting classpath to "export CLASSPATH=/path/:$CLASSPATH" instead of "export CLASSPATH=/path/mysql-connector-java-5.0.8-bin.jar:$CLASSPATH" – Flashman Jan 20 '11 at 15:53

Also, if you can't figure out your classpath issue, you can also just drop the mysql-connector-java-5.0.8-bin.jar into your JRE/lib/ext directory and it will auto-load and you wont need to add it to your classpath because it will be part of the default classloader .

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.