您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

数据库事务使用范例

2025/5/4 2:24:50发布24次查看
传入实体执行(可添加 修改 删除)事务。 idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring( businessdbconnection )); bool result = true ; try { dbhelper.begintransaction(); //主表 te_areamanager manager = new te_areamanager(
传入实体执行(可添加 修改 删除)事务。
idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction(); //主表 te_areamanager manager = new te_areamanager(dbhelper, userinfo); te_areaentity te_areaentity = manager.getobject(dbhelper.sqlsafe(eatxtarea_id)); manager.delete(te_areaentity);//子表 te_area_submanager submanager = new te_area_submanager(dbhelper, userinfo); te_area_subentity te_area_subentity = submanager.getobject(dbhelper.sqlsafe(eatxtarea_id)); submanager.delete(te_area_subentity);//事务提交  dbhelper.committransaction(); } catch(exception ex) {//事务回滚 dbhelper.rollbacktransaction(); result=false; } 可以传入sql语句执行事务idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction(); string commandtext = delete from te_area where id= + dbhelper.sqlsafe(id); dbhelper.executenonquery(sqlstring); commandtext = delete from te_area_sub where id= + dbhelper.sqlsafe(id); dbhelper.executenonquery(commandtext); dbhelper.committransaction(); } catch(exception ex) { dbhelper.rollbacktransaction(); result=false; } 还可以同时传入实体,sql语句idbhelper dbhelper = new oraclehelper(confighelper.getconfigstring(businessdbconnection)); bool result = true; try { dbhelper.begintransaction();//主表 te_areamanager manager = new te_areamanager(dbhelper, userinfo); te_areaentity te_areaentity = manager.getobject(dbhelper.sqlsafe(eatxtarea_id)); manager.delete(te_areaentity);//子表 te_area_submanager submanager = new te_area_submanager(dbhelper, userinfo); te_area_subentity te_area_subentity = submanager.getobject(dbhelper.sqlsafe(eatxtarea_id)); submanager.delete(te_area_subentity); //执行sql语句  string commandtext = delete from jintianda where id= + dbhelper.sqlsafe(id);  dbhelper.executenonquery(commandtext); //事务提交  dbhelper.committransaction(); } catch(exception ex) { //事务回滚 dbhelper.rollbacktransaction(); result=false; }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product