CustomDatabase is a simple Java program that connects to a MySQL server and creates a new database. This project demonstrates how to use JDBC (Java Database Connectivity) to interact with a MySQL database.
- Connects to a MySQL server using JDBC.
- Creates a new database dynamically.
- Implements exception handling for missing drivers and SQL errors.
Before running this project, ensure you have the following installed:
- Java Development Kit (JDK)
- MySQL Server (Ensure it's running)
- MySQL Connector/J (JDBC Driver) (Download Here)
- Download the MySQL Connector/J
.jarfile. - Add it to your project's classpath.
Update the following variables in CustomDatabase.java:
static final String USER = "your_mysql_username";
static final String PASSWORD = "your_mysql_password";
static final String JDBC_URL = "jdbc:mysql://localhost:3306/";javac -cp ".;mysql-connector-java-<version>.jar" CustomDatabase.java
java -cp ".;mysql-connector-java-<version>.jar" CustomDatabase(Replace <version> with the actual version of MySQL Connector/J you downloaded.)
- Add MySQL Connector/J to the classpath.
- Run the
CustomDatabase.javafile.
- If you see "MySQL JDBC Driver not found", ensure the JDBC driver is added to your classpath.
- If you see "Access denied", check your MySQL credentials.
- If database already exists, modify
databaseNameor check if the database was previously created.
🔨 Happy Coding! 🔧