I am currently developing a simple Inventory Management System using Java (Swing GUI) and MySQL database. However, I am encountering issues with connecting my Java application to the database.
Here are the details of my problem:
- I am using JDBC to establish a connection.
- My database name is
inventory_db - I have already created a table named
products - My code compiles without errors, but when I run it, it shows a connection error.
Here is a snippet of my connection code:
Connection conn;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory_db", "root", "");
System.out.println("Connected Successfully");
} catch (Exception e) {
System.out.println(e);
}
The error I am getting is:
java.sql.SQLException: No suitable driver found
Questions:
- What is causing the “No suitable driver found” error?
- How can I properly fix this issue?
- Are there any additional steps required when using MySQL with Java (JDBC)?
- Can you provide a corrected and working version of the connection code?
Leave a Reply
You must be logged in to post a comment.