public class JDBCTest {
@Test
public void test() throws SQLException {
//1.加载驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//2.建立连接
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/cjj1","root", "root");
//3.创建数据库操作对象
Statement statement=connection.createStatement();
//4.执行sql
String sql="insert into t_user values(NULL,'zhangsan',18);";
statement.execute(sql);
statement.close();
connection.close();
}
}
@Test
public void test() throws SQLException {
//1.加载驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//2.建立连接
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/cjj1","root", "root");
//3.创建数据库操作对象
Statement statement=connection.createStatement();
//4.执行sql
String sql="insert into t_user values(NULL,'zhangsan',18);";
statement.execute(sql);
statement.close();
connection.close();
}
}