JDBC statement

public class JDBCDemo2_Statement {
    
    
    @Test
    public void testDML() throws Exception {
    
    //DML是指对数据内容进行修改,对数据的增删改

        String url = "jdbc:mysql:///test230615?useSSL=false";
        String username = "";
        String password = "";
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql = "update account set money = 1000 where id = 1";
        Statement statement = connection.createStatement();
        int count = statement.executeUpdate(sql);
        if (count>0){
    
     //count表示受影响的行数,若为0则表示修改失败
            System.out.println("修改成功!");
        }else {
    
    
            System.out.println("修改失败!");
        }
        connection.close();
        statement.close();
    }

    @Test
    public void testDDL() throws Exception {
    
    //DDL是指对表和库的增删改查

        String url = "jdbc:mysql:///test230615?useSSL=false";
        String username = "";
        String password = "";
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql = "create database db";
        Statement statement = connection.createStatement();
        int count = statement.executeUpdate(sql);
        System.out.println(count);
        connection.close();
        statement.close();
    }
}

猜你喜欢

转载自blog.csdn.net/WuwuwuH_/article/details/131227834
今日推荐