Java drives connection to MySQL database using JDBC:
1. Download driver, import jar Package
2. Load Driver
3. Set up the connection
After the connection is successful, some operations are done on the data in the database
1. Download driver, import jar Package
When you see a corresponding jar package in the JDBC directory, the first step is complete.
2. Load Driver
3. Set up the 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 MySQL JDBC driver System.out.println ("Load driven success!");
catch (Exception e) {System.out.print ("Load 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 th E connection is being made * password:the user ' s password/connection connect = DriverManager
. getconnection ("Jdbc:mysql://localhost:3306/students", "Root", "");
SYSTEM.OUT.PRINTLN ("Database connection successful!");
catch (Exception e) {System.out.print ("Database connection failed!");
E.printstacktrace (); }
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.