我正在尝试使用 <xe:jdbcConnectionManager>
与 <xe:jdbcRowSet>
.这应该工作吗?这本书(XPages 扩展库)似乎暗示应该这样做,但是示例 NSF (XPagesJDBC.nsf) 不包含任何具有该组合的示例。当然,jdbcRowSet 接受 connectionManager
属性。
我收到此错误:
com.ibm.xsp.FacesExceptionEx: Unknown ConnectionManager jdbcConnectionManager1
com.ibm.xsp.extlib.util.JdbcUtil.createManagedConnection(JdbcUtil.java:106)
com.ibm.xsp.extlib.jdbc.model.JdbcRowSetAccessor.findConnection(JdbcRowSetAccessor.java:467)
扩展代码
问题似乎出在 JdbcUtil.java 函数 findConnectionManager() 中。它返回 null,这就是为什么我得到上述异常。这是函数:
public static IJdbcConnectionManager findConnectionManager(FacesContext context, UIComponent from, String name) throws SQLException {
UIComponent c = FacesUtil.getComponentFor(from, name);
if(c!=null) {
return (IJdbcConnectionManager)c;
}
return null;
}
参数
name
不为空,因为它在异常消息中被引用。参数context
根本没有使用。和参数 from
,如果为空,则像这样获取(在第 102 行):from = context.getViewRoot();
.这是抛出异常的函数:
public static Connection createManagedConnection(FacesContext context, UIComponent from, String name) throws SQLException {
if(from==null) {
from = context.getViewRoot(); // ROW 102
}
IJdbcConnectionManager manager = findConnectionManager(context, from, name);
if(manager==null) {
throw new FacesExceptionEx(null,"Unknown ConnectionManager {0}",name); // ROW 106
}
return manager.getConnection();
}
我的代码
所以,这有效:
<xp:this.data>
<xe:jdbcRowSet var="jdbcRowSet1" maxRows="10"
sqlQuery="SELECT * FROM test.reportcode;"
connectionName="mysql_pooled">
</xe:jdbcRowSet>
</xp:this.data>
这不起作用:
<xe:jdbcConnectionManager id="jdbcConnectionManager1"
connectionName="mysql_pooled">
</xe:jdbcConnectionManager>
<xp:this.data>
<xe:jdbcRowSet var="jdbcRowSet1" maxRows="10"
sqlQuery="SELECT * FROM test.reportcode;"
connectionManager="jdbcConnectionManager1">
</xe:jdbcRowSet>
</xp:this.data>
请注意, connectionName 是相同的,并且在 jdbcRowSet 直接使用时可以完美运行。唯一的变化是使用相同的 connectionName 使用对 jdbcConnectionManager 的引用替换该属性。该设置也适用于 jdbcQuery 数据源。
我怎样才能使这项工作?或者可以做到吗?
最佳答案
组件xe:jdbcConnectionManager
当 <xp:this.data>
时还不存在被计算。组件通常使用 XPage 数据源,这可能就是在创建组件之前计算数据源的原因。
您可以尝试设置 connectionManager
例如在 afterPageLoad
事件。
编辑
要检查的一件事是 SPR#MKEE86YD5L Also search for components that are within facets.不确定这是否已修复。
关于xpages - JDBCConnectionManager 可以与 JDBCRowSet 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19932982/