A simple Java application that allows you to search for books from a MySQL database. This app lets users search books based on attributes such as title, author, genre, and year.
Before you begin, ensure you have the following installed:
- Java Development Kit (JDK): Download JDK
- MySQL: Download MySQL
- MySQL Connector/J: This is a JDBC driver for MySQL (included in the project under
libs/mysql-connector-j-9.3.0.jar).
-
Install MySQL if you don't already have it installed.
-
Start MySQL:
- On Windows, run MySQL via the command prompt:
mysql -u root -p
- Provide the password when prompted.
- On Windows, run MySQL via the command prompt:
-
Create Database: Once logged into MySQL, create the
bookdbdatabase:CREATE DATABASE bookdb; USE bookdb;
-
Create Books Table: Create a table to store books in the database:
CREATE TABLE books ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), author VARCHAR(255), genre VARCHAR(100), year INT );
-
Insert Sample Data: Add sample books to the table:
INSERT INTO books (title, author, genre, year) VALUES ('The Great Gatsby', 'F. Scott Fitzgerald', 'Classic', 1925), ('To Kill a Mockingbird', 'Harper Lee', 'Fiction', 1960), ('1984', 'George Orwell', 'Dystopian', 1949);
If you haven’t installed Java, download and install the latest JDK from Oracle's website.
You can verify Java is installed correctly by running:
java -versionClone the repository to your local machine:
git clone https://github.com/PetaSravani/Book-Search-using-Java.git
cd Book-Search-using-JavaThe MySQL Connector/J library is required to connect the Java application to MySQL.
- Download the MySQL Connector/J from here.
- Place the
mysql-connector-j-9.3.0.jarfile in thelibsdirectory of your project (if it doesn't exist, create thelibsfolder).
-
Navigate to the Project Folder:
cd C:/path/to/your/Book-Search-using-Java -
Compile the Java Files:
javac -cp ".;libs/mysql-connector-j-9.3.0.jar" src/Main.java -
Run the Application:
java -cp ".;libs/mysql-connector-j-9.3.0.jar" Main
Book-Search-using-Java/
│
├── libs/
│ └── mysql-connector-j-9.3.0.jar
├── src/
│ ├── Book.java
│ └── Main.java
│──outputs
├── .gitignore
├── Book.iml
└── README.md
The dataset consists of a collection of books with the following attributes:
- title
- author
- genre
- year
Stored in the MySQL database.
- Search by title, author, genre, or year.
- Ensure MySQL server is running.
- Check MySQL username/password.
- Confirm Connector/J is correctly referenced.
This project is licensed under the MIT License.