setParameterList(String ,collection,Type);

本文介绍了一种使用Hibernate通过提供personOid列表来批量更新数据库中多个记录的方法。具体实现包括构造HQL更新语句并设置参数。
部署运行你感兴趣的模型镜像
public void updateByPersonOid(List<String> personOidList) throws DataAccessException {
        StringBuffer hql 
= new StringBuffer();
    
//    hql.append("update Info w set w.Birthday=:Birthday where w.personOid=:personOid");
        hql.append("update Info w set w.FeeUsage=:FeeUsage where w.personOid in (:personOidList)");
        Query query 
= getSession().createQuery(hql.toString());
        query.setString(
"FeeUsage", ENJOY);
                                       
//数据库中的personOid为number
        query.setParameterList("personOidList", personOidList,new StringType());
        query.executeUpdate();
    }

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

### Python + SQLite ```python import sqlite3 # 连接到 SQLite 数据库 conn = sqlite3.connect('example.db') cursor = conn.cursor() # 定义形参 tableNo = 'new_tableNo' # 执行 SQL 代码 update_query = f"UPDATE COMPL_COMPLAINTS SET TABLE_NO_KESU = '{tableNo}' WHERE TABLE_NO = '{tableNo}'" cursor.execute(update_query) # 提交事务 conn.commit() # 关闭连接 conn.close() ``` ### Java + JDBC ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class SQLExample { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/your_database"; String user = "your_username"; String password = "your_password"; try (Connection conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement()) { String tableNo = "new_tableNo"; String updateQuery = "UPDATE COMPL_COMPLAINTS SET TABLE_NO_KESU = '" + tableNo + "' WHERE TABLE_NO = '" + tableNo + "'"; stmt.executeUpdate(updateQuery); } catch (Exception e) { e.printStackTrace(); } } } ``` ### Node.js + MySQL ```javascript const mysql = require('mysql2'); // 创建连接池 const pool = mysql.createPool({ host: 'localhost', user: 'your_username', password: 'your_password', database: 'your_database' }); const tableNo = 'new_tableNo'; const updateQuery = `UPDATE COMPL_COMPLAINTS SET TABLE_NO_KESU = '${tableNo}' WHERE TABLE_NO = '${tableNo}'`; // 执行 SQL 查询 pool.query(updateQuery, (error, results) => { if (error) throw error; console.log('Query executed successfully'); }); // 关闭连接池 pool.end(); ``` ### Ruby + ActiveRecord ```ruby require 'active_record' # 配置数据库连接 ActiveRecord::Base.establish_connection( adapter: 'mysql2', host: 'localhost', username: 'your_username', password: 'your_password', database: 'your_database' ) # 定义模型 class ComplComplaint < ActiveRecord::Base self.table_name = 'COMPL_COMPLAINTS' end tableNo = 'new_tableNo' ComplComplaint.where(TABLE_NO: tableNo).update_all(TABLE_NO_KESU: tableNo) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值