Installing and Using XAMPP on Windows

March 9, 2020

This page contains information that you will find useful as you install XAMPP on your Windows machine and use it with JDBC.

1. Installing XAMPP on Windows

Follow these steps:

  1. Go to https://www.apachefriends.org/index.html.

  2. Download "XAMPP for Windows 7.4.3 (PHP 7.4.3)" (or the latest version) into a folder of your choice. Adjust in the rest of this page if you are using a different version. You will download xampp-windows-x64-7.4.3-0-VC15-installer.exe.

  3. Execute the installer. As you go through the installation process, you will find this page quite helpful.

    If you continue with the XAMPP Control Panel toward the end of the installation, you will get to try the shell command-line utility. Use the following commands:
         # mysql -h localhost -u root    -- To start a client from shell.
    
         MariaDB [(none)]> show databases;  -- One possible command.
         /*
         I tried the above statement/command to see if it worked or not.
         When you start MySQL, you will actually get MariaDB instead.
         MariaDB (not MySQL) is included in XAMPP, but MariaDB is similar
         to MySQL in its interface.  In fact, it is created by the
         ex-MySQL folks, I read.
         */
       
Now, continue with section 2 below.

2. Using a MySQL (MariaDB) Client

In the install folder you will see the following three programs:

Use these to start and stop the server and for the control panel. Try not to start one when one is already running. It would not hurt to try to stop it when it is not running. That would be one way to avoid trying to start another one when one is already running.

Once you start the Control Panel, start MySQL and try the shell associated with it. That is one way to run a MySQL (well, MariaDB) client. Once you start the shell, try the usual SQL statements. You will see some of them in the next section.

3. Trying SQL with MariaDB

Once you start a MariaDB client in a shell, you can try some database commands and SQL statements. Below are some examples:

4. Some More Examples of SQL Queries

5. Using MySQL with Java (JDBC)

Note: This section is written by me, but I have not actually tried it on a machine, but the TAs tried it on their machines and worked for them.

In this section, I describe what you would need to be able to use MariaDB from Java using JDBC. I assume that you have MariaDB (XAMPP) installed.

Find a Java connector, MariaDB Connector/J 2.5 (the latest at this writing) from here. Click on "Download 2.5.4 Stable Now" followed by "MariaDB Connector/J .jar files" ("Universal"). Then, click on "mariadb-java-client-2.5.4.jar". Download it to a folder of your choice. (Pick a folder that will be around since you will use the complete path name of the file below). This is the connector that you will need. The connector enables Java to talk to the database server.

You will need to add that jar file using its complete pathname to the CLASSPATH environment variable. This is how you do it. Try the following if you are using a Windows 10 machine. For other versions of Windows, find a way that works:

     Start (the four square thing at the lower-left corner)
  -> Control Panel
  -> System and Security
  -> System
  -> Advanced System Settings (on the left column)
  -> Environment Variables
You will see User variables and System variables. Under System variables you may or may not see CLASSPATH. Select it if exists and edit to add that jar file using its complete pathname to the end of the value of CLASSPATH preceded by a semicolon. If you don't see CLASSPATH, then use "New..." and add CLASSPATH as "Variable name" and the complete path of the jar file as "Variable value".

Now, download, compile, and run Bank1.java which will bring in DB.java. They use JDBC. Be sure to read the comments at the top of Bank1.java to see how to run it.

and read the instructions at the top of Bank1.java to run and test your JDBC capability. Also read DB.java to see how a database driver is loaded and how a connection is established.

If This Does NOT Work and nothing else could be tried to make it work, uninstall XAMPP and MariaDB and then follow the instructions very carefully from the very beginning again. Some students had to do that and it worked for them.

That's it!