Hello, there is a class that connects to the database. Using eclipse I create a jar file in which this class and mysql connection, when I run jar, I constantly see the error java.lang.ClassNotFoundException: com.mysql.jdbc:Driver tell me what am I doing wrong?
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Solution1 { private static Connection connection = null; private static Statement statement = null; private static String url = "jdbc:mysql://localhost:3306/example?autoReconnect=true&useSSL=false"; public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(url, "admin", "admin"); statement = connection.createStatement(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM Example"); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { System.out.println(resultSet.getString(2)); } } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } as a result, jar contains:
- main package in which class
- jar file connection
- META-INF folder (generated automatically)