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();
}
}
JDBC statement
最新推荐文章于 2024-10-01 09:29:45 发布
该Java程序演示了如何使用JDBC进行数据库操作,包括DML(DataManipulationLanguage)对数据的增删改和DDL(DataDefinitionLanguage)对表和库的创建。在DML部分,它更新了一个account表中的记录;在DDL部分,它创建了一个新的数据库db。
摘要由CSDN通过智能技术生成