在XPage中使用JDBC无法在MSSQL中执行查询

时间:2014-03-23 10:45:43

标签: sql-server jdbc xpages

我在xpage中使用JDBC Microsoft SQL驱动程序从MS SQL服务器获取数据 驱动程序使用更新站点安装,并成功加载到OSGI

我还在应用程序的webcontent \ webinf \ jdbc文件夹中添加了一个包含凭据的sqlserver.jdbc

当我尝试使用@JdbcDbColumn访问sql表时它工作正常

var con=@JdbcGetConnection("sqlserver");
@JdbcDbColumn(con,"PrTr","Descr")

但是当我尝试执行像这样的查询时

var con=@JdbcGetConnection("sqlserver");
var query="SELECT * FROM PrTr";
var rs=@JdbcExecuteQuery(con,query);
....

我得到一个堆栈跟踪错误(在第3行)有很多错误行,突出的行是这些

  

com.ibm.jscript.InterpretException:脚本解释器错误,行= 4,   col = 8:执行函数' @ JdbcExecuteQuery'

时出错      

java.lang.ArrayIndexOutOfBoundsException

我还尝试将视图面板连接到JDBCQuery数据源,但之后我只得到一个500错误而没有堆栈跟踪

SQL服务器与xpages

不在同一台Windows服务器上 在stacktrace / tracelog中有一行看起来像这样

  

java.security.AccessController.doPrivileged(AccessController.java:362)

但不确定它是错误还是仅供参考,如果它与查询有关。即如果存在安全问题。

我需要帮助才能理解为什么我可以执行@JDBCDbColumn而不是@JDBCExecuteQuery

btw我刚检查了SQLLog,没有看到任何与我的查询相关的条目

这是完整的堆栈跟踪

  

com.ibm.xsp.exception.EvaluationExceptionEx:执行时出错   JavaScript计算表达式       com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:132)       javax.faces.component.UIOutput.getValue(UIOutput.java:159)       com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1122)       com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:97)       com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:180)       javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:858)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1317)       com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1255)       com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:651)       com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:321)       com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:336)       com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)       com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)       com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)       com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:270)       com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:261)       com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)       com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)       com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)       com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)       com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ AdapterInvoker.invokeServlet(ComponentModule.java:853)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ ServletInvoker.doService(ComponentModule.java:796)       com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)       com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)       com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)       com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)   com.ibm.jscript.InterpretException:脚本解释器错误,行= 3,   col = 10:执行函数时出错' @ JdbcExecuteQuery'       com.ibm.xsp.extlib.javascript.JdbcFunctions $ NotesFunction.call(JdbcFunctions.java:389)       com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)       com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)       com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82)       com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)       com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)       com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435)       com.ibm.jscript.JSExpression.access $ 1(JSExpression.java:424)       com.ibm.jscript.JSExpression $ 2.run(JSExpression.java:414)       java.security.AccessController.doPrivileged(AccessController.java:362)       com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410)       com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251)       com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234)       com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:222)       com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:194)       com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:78)       javax.faces.component.UIOutput.getValue(UIOutput.java:159)       com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1122)       com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:97)       com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:180)       javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:858)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1317)       com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1255)       com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:651)       com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:321)       com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:336)       com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)       com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)       com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)       com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:270)       com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:261)       com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)       com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)       com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)       com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)       com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ AdapterInvoker.invokeServlet(ComponentModule.java:853)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ ServletInvoker.doService(ComponentModule.java:796)       com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)       com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)       com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)       com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)   java.lang.ArrayIndexOutOfBoundsException:数组索引超出范围:2       com.ibm.jscript.types.FBSValueVector.get(FBSValueVector.java:76)       com.ibm.xsp.extlib.javascript.JdbcFunctions $ NotesFunction.call(JdbcFunctions.java:267)       com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)       com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)       com.ibm.jscript.ASTTree.ASTVariableDecl.interpret(ASTVariableDecl.java:82)       com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)       com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)       com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435)       com.ibm.jscript.JSExpression.access $ 1(JSExpression.java:424)       com.ibm.jscript.JSExpression $ 2.run(JSExpression.java:414)       java.security.AccessController.doPrivileged(AccessController.java:362)       com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410)       com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251)       com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234)       com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:222)       com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:194)       com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:78)       javax.faces.component.UIOutput.getValue(UIOutput.java:159)       com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1122)       com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:97)       com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:180)       javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:858)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:853)       com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1317)       com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1255)       com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:651)       com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:321)       com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:336)       com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)       com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)       com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)       com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:270)       com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:261)       com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)       com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)       com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)       com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)       com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ AdapterInvoker.invokeServlet(ComponentModule.java:853)       com.ibm.designer.runtime.domino.adapter.ComponentModule $ ServletInvoker.doService(ComponentModule.java:796)       com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)       com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)       com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)       com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)       com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)       com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)

2 个答案:

答案 0 :(得分:0)

前段时间我遇到过这个问题,列名是大写字母,用于扩展库代码中的方法 - > How to get XPages and JSON to not put variable names in Uppercase

我不确定它是否是同一个问题,但可能值得研究。

答案 1 :(得分:0)

要了解它是否存在安全问题,您可以允许Java的所有权限。在java.pol文件夹中创建jvm/lib/ext/文件,然后添加:

grant {
  permission java.security.AllPermission;
};

(当你完成后不要忘记重启服务器)

我通过将正确的驱动程序Jar文件包含到数据库中来完成自定义JDBC连接,我需要这样做才能使它工作。