Thursday, July 21, 2011

MySQL versus Derby - file locations

If you use the embedded driver for Derby, the default location for any database created is in the same folder as the driver, derby.jar. In the case of my financial mini-app I placed this package in the same folder as my code files, and I gave it a name derived from the function of the code - fin. When I ran the code, Derby created a subfolder called dbFin to contain the data files. It was all very convenient.

According to my understanding of MySQL:

  1. The server has to running. By default, when you install it starts as a service with Windows. R.G. Baldwin, in 2004, deselected this option. Computers have moved on since then, so I left it in, and the four cores of my Ci5 processor (boasting a little here, because a couple of years ago I was still using a PII) still run at 0-1% as they did before the installation. So I don't need to worry about getting the server running, because it is running.
  2. The JDBC driver, MySQL Connector/J, needs to be installed on your computer and included in the class path. R.G. Baldwin placed it in his jre libraries folder. My preferred option would be to place the mysql-connector-java-3.0.15-ga-bin.jar file with my own code files, and I shall try that as a first option.

In order to run my existing code:

  1. I need a copy of the Java Development Kit (JDK) installed. Again, I've had it before, but I checked on the (now) Oracle Java Downloads page for the current version. I had JDK update 3, and the current release is update 26. As I happened to check during off peak hours for my ISP, I downloaded the current release and installed that.
  2. Before running any code I need to set a path to the JDK binaries. This can be done as an environment variable, or just prior to runtime. I usually use a batch file, which also takes me to the locale of my own code.
  3. In the command to run my code, I need to set the classpath for my own binaries and for the JDBC driver. Again, I usually use a one line batch file, because it is easy to edit and run.

In order to convert my code to use MySQL:

  1. I need to modify my classpath to point to the MySQL Connector/J driver, and of course ensure that the mysql-connector-java-3.0.15-ga-bin.jar file is actually where the classpath is pointing.
  2. I need to modify two lines of my own connection code, to load the MySQL JDBC driver, and to refer to the MySQL database. I also need to add a command to create the database, if I have not already done so.

My next entry will record the execution of these steps, and the results of doing so.

No comments: