{"inframe":false,"title":"访问数据库","hidden":false,"roles":{"dev":1},"children":[{"configs":{"serverScript":"//*** 比较经典的数据库访问代码片断 ***\nvar statement, connection = DbUtil.getConnection( /*jndi，缺省表示默认数据库，获取一个新的连接*/ );\n//var conn=DbUtil.getConnection(request); //获取本次请求共享的连接，使用该方法获取的连接系统会在请求结束后自动释放\ntry {\n  connection.setAutoCommit(false);\n  statement = connection.prepareStatement('update WB_MISC set INT_FIELD=123 where 1=0');\n  statement.executeUpdate();\n  //其他业务代码\n  connection.commit();\n} catch (e) {\n  Wb.error(e.message);\n} finally {\n  //if(resultSet) DbUtil.close(resultSet);\n  if (statement) DbUtil.close(statement);\n  if (connection) DbUtil.close(connection); //该方法会自动回滚事务（如果未显式提交）并关闭连接\n}\napp.send('请参考module serverScript源码');","itemId":"module"},"children":[],"expanded":false,"type":"module"}],"pageLink":"","iconCls":""}