[Java] import java. SQL. *; public class ConnDatabase {private static final String DBDRIVER = "com. microsoft. sqlserver. jdbc. SQLServerDriver "; private static final String DBURL =" jdbc: sqlserver: // localhost: 1433; DatabaseName = School1 "; private static final String DBUSER =" sa "; private static final String DBPWD = "sa"; // Refresh public static void Query (ResultSet rs) throws Exception {System. out. println ("No \ t Name \ tAge \ tSex "); // student ID, Name, age, gender while (rs. next () {String no = rs. getString ("No"); String name = rs. getString ("Name"); int age = rs. getInt ("Age"); String sex = rs. getString ("Sex"); System. out. println (no + "\ t" + name + "\ t" + age + "\ t" + sex);} public static void main (String [] args) throws Exception {Class. forName (DBDRIVER); // load the driver Connection conn = DriverManager. getConnection (DBURL, DBUSER, DBPWD); // connect to the database Sta Tement stmt = conn. createStatement (); // database operation // CREATE a TABLE stmt.exe cute ("create table Stu5" + "(No varchar (20) primary key," + "Name varchar (10 ), "+" Age int, "+" Sex varchar (2) "); String sqlResult =" select * from Stu5 "; ResultSet rs = stmt.exe cuteQuery (sqlResult ); query (rs); // Add stmt.exe cuteUpdate ("insert into Stu5 (No, Name, Age, Sex)" + "VALUES ('20170101', 'day', 19, 'femal') "); rs = stmt.exe cuteQuery (sqlResult); Query (rs );/ /Change stmt.exe cuteUpdate ("UPDATE Stu5 SET Age = 20 WHERE Name = 'chen Yan'"); rs = stmt.exe cuteQuery (sqlResult); Query (rs ); // Delete stmt.exe cuteUpdate ("delete from Stu5 WHERE Name = 'chen Yan'"); rs = stmt.exe cuteQuery (sqlResult); Query (rs); rs. close (); stmt. close (); conn. close () ;}} PS: private static final String DBURL = "jdbc: sqlserver: // localhost: 1433; DatabaseName = School1"; this line of code has two points to note: 1. DBURL needs to be changed according to the actual situation. 2. DatabaseName = School1. Previously I wrote DatabaseName = 'school1 ', and the result was wrong. It took me a long time to find out and correct this small mistake. I hope you will not make the same mistake as me.