Steps to connect to MySQL database using JDBC driver in Java:
1. Download the driver and import the jar package
2. Load the driver
3. Set up connection
After the connection is successful, some operations on the data in the database
1. Download the driver and import the jar package
When you see the corresponding jar package in the jdbc directory, it means that the first step has been completed.
2. Load the driver
3. Set up connection
import java.sql.Connection; import java.sql.DriverManager; public class DB_Helper { public static void main(String[]args) { try { Class.forName("com.mysql.jdbc.Driver"); // Load the MYSQL JDBC driver System.out.println("Loading driver successful!"); } catch (Exception e) { System.out.print("Loading driver failed!"); e.printStackTrace(); } try { //public static Connection getConnection(String url,String user,String password) /* * url : a database url of the form jdbc:subprotocol:subname * user : the database user on whose behalf the connection is being made * password : the user's password */ Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "root", ""); System.out.println("Database connection succeeds!"); } catch (Exception e) { System.out.print("Database connection failed!"); e.printStackTrace(); } } } The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.