java增删改查语句
时间: 2024-01-12 14:20:41 浏览: 73
以下是Java中增删改查语句的示例:
1. 插入数据
```java
String sql = "INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)";
Statement statement = connection.createStatement();
int rows = statement.executeUpdate(sql);
```
2. 修改数据
```java
String sql = "UPDATE table_name SET column1 = value1, column2 = value2 WHERE some_column = some_value";
Statement statement = connection.createStatement();
int rows = statement.executeUpdate(sql);
```
3. 删除数据
```java
String sql = "DELETE FROM table_name WHERE some_column = some_value";
Statement statement = connection.createStatement();
int rows = statement.executeUpdate(sql);
```
4. 查询数据
```java
String sql = "SELECT column1, column2, column3 FROM table_name WHERE some_column = some_value";
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(sql);
while (result.next()) {
String column1 = result.getString("column1");
int column2 = result.getInt("column2");
Date column3 = result.getDate("column3");
// 处理查询结果
}
```
阅读全文