JDBC statement

该Java程序演示了如何使用JDBC进行数据库操作,包括DML(DataManipulationLanguage)对数据的增删改和DDL(DataDefinitionLanguage)对表和库的创建。在DML部分,它更新了一个account表中的记录;在DDL部分,它创建了一个新的数据库db。
摘要由CSDN通过智能技术生成
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();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WuwuwuH_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值