Java Programming: Database Access

On the SUN workstations, java files are located at /usr/java
I believe that the system path includes access to /usr/java/bin but if you want to make sure, you can add the line

PATH=$PATH:/usr/java/bin; export PATH

to your .profile file in your top level directory

These are the steps to connect to mysql on jaguar.ecst.csuchico.edu (same as ect-unix.ecst.csuchico.edu).

  1. Use this link to update your existing account to add MySQL to your account capabilities. If this does not work, Email Sys Admin - Elbert (echan@csuchico.edu) to get an account for mysql (He may want some of the same information when you get a UNIX account here.)

  2. Create a file named .profile in your home directory (this is the directory where you are when you first log in) on jaguar that has this line in it:

    CLASSPATH=./:/usr/java/lib/mysql-connector-java-5.1.5-bin.jar; export CLASSPATH

    (or download the .jar here and put in the same directory as your code - hmmm, this file has an extension .jar but when Windows downloads it it changes it to .zip Make sure that your classpath and actual file name are the same)

  3. Then the url that you want to connect to from the java database code should be

    jdbc:mysql://db.ecst.csuchico.edu:5551/databasename

    db.ecst.csuchico.edu is the actual server where mysql is at and 5551 is the port number.
    Also you should change databasename to the database/username that Elbert gives you to use. Usually it is your unix username. For example, I use

    String url = "jdbc:mysql://db.ecst.csuchico.edu:5551/amk";

    The line for your code to get the appropriate driver: Class.forName("com.mysql.jdbc.Driver");

    I think that that's all that one needs to connect to mysql through jaguar.

  4. The program that you are running must be on jaguar. Note that ftp is turned off on jaguar - you can only get on through ssh
    Partly because of the way that the ports and everything are locked down and you cannot get to the database except from this access, but also since you now are pointing to the driver from your .profile there.
    (Hmm, just now I ran it on tiglon so if you cannot get to jaguar, give tiglon a try)

  5. Remember that the public_html folder is really a symbolic link to the web server (a completely different machine -lynx I think). SO, to run your java connections to your database on Unix, you need to do it from a folder NOT in your public_html to make sure that you are allowed access

  6. Finally, Eclipse is also on jaguar at /opt/eclipse if you want to run your programs on campus


Testing without GUI's or using XMing to see GUIs

You can always ssh to jaguar and test your code directly and easily if you do not have a GUI.

You could also test your java code with GUIs and connectivity directly off of jaguar:
For displaying your GUIs on your local machine when running from a remote machine, see here


To connect to your local MySql in Eclipse set up on your home machine

If you have downloaded MySql to your home machine, to test your code and db connections you can use the URL

for example, who knows why, but at home I have This worked for me.

As noted in class, you might need to get your machine's IP address (how?) and use it rather than localhost for the URL...and you might want to set up a new database with a name you know so you do not need to know the default name. Both of these can be done through the MySQL admin tool.


I also have an email from a student working from home - trying to connect to jaguar who had problems. I will include the text here in case it might help you.
However it might be a good idea to just ssh into jaquar and run the database from there since firewalls seem to be a problem connecting from elsewhere to the database.

Elbert told me basically the same thing that you did, ie the JDBC connection string you quoted. 
However I just tried to directly connect from my computer (both in and out of VPN) to the DB with no success. 
I'm getting errors like this which probably means the port is blocked by the firewall: 

java.net.ConnectException
MESSAGE: Connection timed out: connect


I just did some more research into getting around this and found 

http://forge.mysql.com/wiki/MySQL_Proxy

All I need to do is ssh onto jaguar, and run

./mysql-proxy \

  --proxy-backend-addresses=db.ecst.csuchico.edu:5551 \

  --proxy-address=jaguar.ecst.csuchico.edu:12340 &

 

Then I can connect from my VPN-ed home computer with a connection like:

jdbc:mysql://jaguar.ecst.csuchico.edu:12340/username



(Reminder to me: links to this page at 1, 2, and 3 so I remember to remove them when Oracle is back up)