Home > database > The IDEA of importing the JDBC package
The IDEA of importing the JDBC package
Time:11-22
The import has been unsuccessful
import java.sql.*;
Public class JdbcDemo1 { Public static void main (String [] args) throws ClassNotFoundException, SQLException { //1. Import the driver jar package //2. The registration drive Class.forname (". Com. Mysql. Cj. JDBC Driver "); //Class. Class.forname (org. GJT. Mm. Mysql. "Driver"); //3. Access to the database connection object The Connection conn= DriverManager. GetConnection (" JDBC: mysql//localhost: 3306/school ", "root", "123456"); //4. Define the SQL statement String SQL="update students set ` name `='sora aoi' where id=4"; //5. Access to objects of executing SQL Statement The Statement STMT=conn. CreateStatement (); //6. Execute SQL Int count=STMT. ExecuteUpdate (SQL); //7. Process the results System. The out. Println (count); //8. Release resources STMT. Close (); conn.close(); } }
An error is as follows:
Code should be no problem, the jar has import
Online solutions are tried, it won't work, learn Mysql card here, ill, a great god for help
CodePudding user response:
import java.sql.*;
Public class JdbcDemo1 { Public static void main (String [] args) throws ClassNotFoundException, SQLException { //1. Import the driver jar package //2. The registration drive Class.forname (". Com. Mysql. Cj. JDBC Driver "); //Class. Class.forname (org. GJT. Mm. Mysql. "Driver"); //3. Access to the database connection object The Connection conn= DriverManager. GetConnection (" JDBC: mysql//localhost: 3306/school ", "root", "123456"); //4. Define the SQL statement String SQL="update students set ` name `='sora aoi' where id=4"; //5. Access to objects of executing SQL Statement The Statement STMT=conn. CreateStatement (); //6. Execute SQL Conn. The open (); Int count=STMT. ExecuteUpdate (SQL); //7. Process the results System. The out. Println (count); //8. Release resources STMT. Close (); conn.close(); } }