0

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?

AeroDroid
  • 101
  • 1

2 Answers2

0

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.

Flashman
  • 1,311
  • 10
  • 9
  • 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 02: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
0

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 .

djangofan
  • 4,172
  • 10
  • 45
  • 59