The Gym Software is a network application, based in Java, which utilises multi-threaded programming and is connected to a database. The software implementation will enable staff members to add, update, delete and view the bookings of each client.
With the use of multi-threading, the Gym Software will be accessible to mutiple clients to connect at the same time and interact with the database.
JDK version 11 is used for this project as it includes the JavaFX library. Download it here.
For Windows:
set JAVA_HOME="C:\[Path to folder]\Java\jdk-11.0.14
Enter the Environment Variables in System Properties.
Add %JAVA_HOME%\bin into Path.
%JAVA_HOME%\bin
MariaDB Server is one of the most popular open source relational databases. It’s made by the original developers of MySQL and guaranteed to stay open source. It is part of most cloud offerings and the default in most Linux distributions. Download it here.
The five tables below will be used to store information in the database.
Trainer | Client | Specialism | Booking | TrainerSpecialism | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
A JDBC driver is a software component enabling a Java application to interact with a database.
To connect with individual databases, JDBC (the Java Database Connectivity API) requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database. Download the JDBC Driver here.
A Server-Client setup refers to socket programming in Java where a client sends messages to the server and the server shows them using a socket connection.
A socket in Java is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.
The server will instantiate its object and wait for the client request. Once the client sends the request, the server will communicate back with the response.
The ServerSocket is binded to the port number 8080, which is passed as an argument to the constructor of the class ServerSocket.
final int PORT = 8080;
try (ServerSocket serverSocket = new ServerSocket(PORT)) {
while (true) {
Socket socket = serverSocket.accept();
new Thread(new ServerRunnable(socket)).start();
}
}
The getOutputStream() method is used to send the output through the socket.
OutputStream outputStream = socket.getOutputStream();
The getInputStream() method is used to receive messages, through the socket, from the Client side.
InputStream inputStream = socket.getInputStream();
Database connection is set in the ServerRunnable.java.
private Connection connection = Database.connectDb();
In order to establish a connection to the server, a socket is required.
String hostName = "localhost";
int port = 8080;
Socket socket = new Socket(hostName, port);
where the first argument is the IP addres of Server (127.0.0.1/localhost) and the second argument is the TCP port which will be the same on the server-side.
Testing shows that the software has meet its requirements and it is printing the expected output.
Before sending data to the server, the client side must validate the user input. In the gym software, regex expressions are used to validate all user inputs from console.
^[B][0-9]{3}+$
The ^ symbol means the start of the string which is the user input and $ sign is end of string. In the regex above, the string must always start with a capital B and continue with only 3 numeric values.
Examples:
Good format: B001, B123, B999
Bad format: C001, B0001, JC21, BB01
The same format is used to validate the trainerID, SpecialismID and ClientID.
\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[[01])*
The “\d{4}” ensures that the user input for year is YYYY. The “(0?[1-9]|1[012])” part checks if user months input is between 01 to 12. And the last part allows only numbers between 01 to 31 to be accepted.
([01]?[0-9]|2[0-3]):[0-5][0-9]
It ensures that the time is between 00:00 to 23:59. Even 9:0 is accepted but it will be reconverted to 09:00 in the table booking.
After installing MariaDB, import the table from SQL folder, to the database, using the following command.
mysql -u root -p
source C:\[Path to folder]\SQL\GymTable.sql
The Server.java will have to be executed first, then the Client.java.
javac *.java
java Server
java Client
Use the following commands in order to use the software.
ADD <BookingID> <BookingDate> <StartTime> <ClientID> <SpecialismID> <TrainerID>
LISTALL
LISTPT <TrainerID>
LISTCLIENT <ClientID>
LISTDAY <BookingDate>
UPDATE UPDATE <BookingDetail> <NewValue> <BookingID>
DELETE <BookingID>
👤 Rohan Bhautoo
- Github: @rohan-bhautoo
- LinkedIn: @rohan-bhautoo
Give a ⭐️ if this project helped you!