Hello. Please help solve the problem: you need to connect the JDBC driver - I want to set up a connection with MySQL in Java . I downloaded the connector here https://dev.mysql.com/downloads/connector/j/ and I don’t understand (very weak English) where to insert this file, how to connect it and what is CLASSPATH and how to register it. Help, please understand.
The code looks like this:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { // JDBC URL, username and password of MySQL server private static final String url = "jdbc:mysql://localhost:3306/java_connect"; private static final String user = "root"; private static final String password = ""; // JDBC variables for opening and managing connection private static Connection con; private static Statement stmt; private static ResultSet rs; public static void main(String args[]) { String query = "select count(*) from books"; try { // opening database connection to MySQL server con = DriverManager.getConnection(url, user, password); // getting Statement object to execute query stmt = con.createStatement(); // executing SELECT query rs = stmt.executeQuery(query); while (rs.next()) { int count = rs.getInt(1); System.out.println("Total number of books in the table : " + count); } } catch (SQLException sqlEx) { sqlEx.printStackTrace(); } finally { //close connection ,stmt and resultset here try { con.close(); } catch(SQLException se) { /*can't do anything */ } try { stmt.close(); } catch(SQLException se) { /*can't do anything */ } try { rs.close(); } catch(SQLException se) { /*can't do anything */ } } } } Worth IDEA Intelij , when you run the program in the console, it gives: No suitable driver found for jdbc:mysql://localhost:3306/java_connect
The database is created, Java is configured of course.


