是否可以使用 Java 为 Maximo 编写纯 sql 语句? 目前我使用 myObj.setWhere("employee = 'brian'");
但我想做的是:
myObj.xxx("select * from employee where name = 'brian'");
有这样的功能吗?
最佳答案
虽然我强烈反对,但您可以直接运行 SQL 语句,而无需自己处理驱动程序管理器。您可以只向 Maximo 请求连接。
大多数时候(如以下示例所示),Maximo 已经为您要运行的语句提供了功能,或者您将选择 Maximo 作为基本 ORM 无法处理的字段子集。在这些情况下,您不会想这样做。
Connection con = null;
try {
con = getMboServer().getDBConnection(getUserInfo().getConnectionKey());
PreparedStatement stmnt = con.prepareStatement("update asset set description = 'Hello World'");
stmnt.execute();
stmnt = con.prepareStatement("select count(*) from asset");
if (stmnt.execute()) {
ResultSet results = stmnt.getResultSet();
if (results.next()) {
int count = results.getInt(1);
}
}
} catch (SQLException e) {
logger.error("There was an 'SQLException' exception while getting the count of assets; The error is:\n", e);
} finally {
if (con != null) {
getMboServer().freeDBConnection(getUserInfo().getConnectionKey());
}
}
关于java - 在 IBM Maximo 中使用 SQL 语句,使用 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21735110/