This is the pure java code snippets. I'm trying to connecting jdbc to the project all the crud operation is excuting under the main method and their is error called classnotfound exception.
public class Appinitializer {
public static void main(String[] args) {
// save
try {
Customer customer = new Customer(1001, "chamithu", "Panadura", 25000, new Date());
if (saveCustomer(customer)) {
System.out.println("Success!");
} else {
System.out.println("Try Again!");
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
// save
}
private static boolean saveCustomer(Customer c) throws ClassNotFoundException, SQLException {
String sql = "INSERT INTO customer VALUES (?,?,?,?,?)";
PreparedStatement preparedStatement = getConnection().prepareStatement(sql);
preparedStatement.setLong(1, c.getId());
preparedStatement.setString(2, c.getName());
preparedStatement.setString(3, c.getAddress());
preparedStatement.setDouble(4, c.getSalary());
preparedStatement.setObject(5, c.getDOB());
return preparedStatement.executeUpdate() > 0;
}
private static Connection getConnection() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost:3306/hibernatedb", "root", "1234");
}
}
This is the error occurred when I run the program.