This page contains information that you will find useful as you install XAMPP on your Windows machine and use it with JDBC.
Follow these steps:
# 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. */
In the install folder you will see the following three programs:
Once you start a MariaDB client in a shell, you can try some database commands and SQL statements. Below are some examples:
MariaDB> show databases; // don't forget the ';'
MariaDB> create database artlee;
MariaDB> grant all privileges on database.* to user@localhost identified by 'password'; // don't forget the single quotes.where database is the name of a database, user is the name of a new user, and password is a password. For example, I used artlee, art, and lee respectively.
MariaDB> grant all privileges on database.* to user@"%" identified by 'password';where @"%" acts as a wildcard for access to the database from any client machine. Here again database is the name of a database, user is the name of a user, and password is a password. For example, I used artlee, art, and lee respectively.
MariaDB> help;
MariaDB> use artlee;
MariaDB> drop database if exists artlee;
MariaDB> source c:/alee/cse305/db/db.sql;Take a look at the content of the script file db.sql. By the way, how would you create a script file? Use your favorite text editor.
MariaDB> quit; or MariaDB> exit;
mysql> drop database if exists artlee;
mysql> create database artlee;
MariaDB> use artlee;
MariaDB> create table Accounts (ID INTEGER, Balance INTEGER);
MariaDB> SELECT * FROM Accounts;Use this to see if insert worked or not when you try inserts below.
MariaDB> insert into Accounts VALUES (1, 11); MariaDB> insert into Accounts VALUES (2, 22); MariaDB> insert into Accounts VALUES (3, 33);
MariaDB> SELECT Sum(Balance) FROM Accounts;
MariaDB> create table Names (id integer, dob date); MariaDB> insert into Names values (1, "2020-03-09"); MariaDB> insert into Names values (2, "2018-03-20"); MariaDB> insert into Names values (3, "2017-01-20");
MariaDB> SELECT * FROM Names, Accounts; -- (+)Use '--' to add a comment.
MariaDB> SELECT * FROM Names, Accounts WHERE Names.ID = Accounts.ID;
MariaDB> SELECT * FROM Names, Accounts WHERE Names.ID = Accounts.ID AND DOB < Date("2018-01-01");
MariaDB> SELECT Names.id, Balance, DOB from Names, Accounts WHERE Names.ID = Accounts.ID AND DOB < Date("2018-01-01");
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 VariablesYou 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.
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!