注解介绍:
1. @Before
在测试方法运行前运行
2. @After
在测试方法运行后运行
3. @Test
可以进行测试的方法
public class JUntil {
Connection connection;
PreparedStatement preparedStatement;
@BeforeEach
public void init() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/scott?useUnicode=true&characterEncoding=UTF-8";
connection = DriverManager.getConnection(url,"root","root");
}
@Test
public void test_update() throws SQLException {
preparedStatement = connection.prepareStatement("update sort set sname= ? where sid = ?");
Scanner scanner = new Scanner(System.in);
scanner.next();
preparedStatement.setString(1,"手机");
preparedStatement.setInt(2,7);
preparedStatement.executeUpdate();
}
@AfterEach
public void after(){
System.out.println("所有测试以后");
}
}