- Download from: https://dev.mysql.com/downloads/mysql/
- Install MySQL Server and MySQL Workbench
Windows:
- Open Services (services.msc)
- Find "MySQL80" or similar
- Right-click → Start
- OR: Run
net start MySQL80in Command Prompt (as Administrator)
Verify MySQL is running:
mysql -u root -pOpen MySQL Command Line or Workbench and run:
-- Create database
CREATE DATABASE IF NOT EXISTS project3;
-- Use the database
USE project3;
-- Create game table
CREATE TABLE IF NOT EXISTS game (
user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user VARCHAR(50) NOT NULL UNIQUE,
scores INT DEFAULT 0,
number_of_games_played INT DEFAULT 0
);
-- Insert test data (optional)
INSERT INTO game (user, scores, number_of_games_played) VALUES
('yusra', 0, 0),
('mama', 0, 0),
('sadia', 0, 0);Open Game.java and find the Connectivity class:
private static final String URL = "jdbc:mysql://localhost:3306/project3";
private static final String USER = "root";
private static final String PASSWORD = "YOUR_MYSQL_PASSWORD"; // Change this!Replace YOUR_MYSQL_PASSWORD with your actual MySQL password (default is often blank or "root")
Make sure you have the MySQL connector jar file. If you get "Driver not found" error:
- Download: https://dev.mysql.com/downloads/connector/j/
- Extract the JAR file
- Add it to your Java classpath or IDE project
- MySQL is not running
- Wrong hostname (should be localhost)
- Wrong port (should be 3306)
- Wrong password
- Update PASSWORD in Connectivity class
- Database not created
- Run the SQL commands above
- MySQL JDBC driver not installed
- Download connector/J from MySQL website
When you run the Game, it will automatically test the database connection and show an error if it fails.
Good luck! 🎮