Implementation steps:
1. Import Drive Jar Package
2. Registration driver.
3. Get the database Connection object Connection
4. Defining SQL statements
5. Get the object that executes SQL Statement
6. Execute SQL. Get return value
7. Process the results.
8. Release resources.
public static void Main (string[] args) throws ClassNotFoundException, sqlexcepti{ //Register driver class.forname (" Com.mysql.jdbc.Driver "); Gets the Connection object Connection conn = drivermanager.getconnection ("Jdbc:mysql:///mydb", "root", "1234"); Gets the object that executes the SQL Statement Statement = Conn.createstatement (); Execute SQL String sql = "INSERT INTO Stu (SID, Name, Sal) VALUES (38, ' hehe ', 56.89)"; int count = statement.executeupdate (sql); The representative means the number of rows affected //Processing result System.out.println (count); Release Resources Statement.close (); Conn.close (); }}
Note: You need to use Mysql-connector-java-5.1.7-bin.jar
JDBC Quick Start