给我写一个jpa的增删改查代码
时间: 2023-03-07 15:51:23 浏览: 106
答:public class JPATest {
public static void main(String[] args) {
// 增加
String sql = "insert into tableName (field1, field2) values(?, ?)";
Object[] params = {"value1", "value2"};
int rowCount = JPAUtil.executeUpdate(sql, params);
// 删除
String deleteSql = "delete from tableName where field3=?";
Object[] deleteParams = {"deleteValue"};
int deleteRowCount = JPAUtil.executeUpdate(deleteSql, deleteParams);
// 修改
String updateSql = "update tableName set field4=? where field5=?";
Object[] updateParams = {"updateValue", "value5"};
int updateRowCount = JPAUtil.executeUpdate(updateSql, updateParams);
// 查询
String querySql = "select * from tableName where field6=?";
Object[] queryParams = {"queryValue"};
List<Map<String, Object>> results = JPAUtil.executeQuery(querySql, queryParams);
}
}
阅读全文