简体   繁体   English

jTDS +存储过程+ prepareSQL =嵌套级错误?

[英]jTDS + stored procedures + prepareSQL = nesting level error?

Situation 情况
I have a (Tomcat) Java web application using jTDS to connect to a MSSQL 2008 database. 我有一个(Tomcat)Java Web应用程序使用jTDS连接到MSSQL 2008数据库。 This Java application executes 99% of its MSSQL stored procedures using user input. 此Java应用程序使用用户输入执行99%的MSSQL存储过程。

Problem 问题
The jTDS driver replies sometimes (at different places in the application) with error: jTDS驱动程序有时会(在应用程序的不同位置)回复错误:

Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32). 超出最大存储过程,函数,触发器或视图嵌套级别(限制32)。

We can avoid this by adding prepareSQL=0 to the jTDS connection string. 我们可以通过将prepareSQL=0添加到jTDS连接字符串来避免这种情况。 Then the error goes away everywhere, but with all other values of prepareSQL , the error stays. 然后错误随处可见,但是对于prepareSQL所有其他值,错误仍然存​​在。 I don't know how many stored procedure nesting levels jTDS adds, but apparently it's too much for our application. 我不知道jTDS添加了多少存储过程嵌套级别,但显然它对我们的应用来说太多了。

Questions 问题

  1. With only stored procedures to execute, of course using Prepared Statements in the Java code, how much effect does prepareSQL=3 (or prepareSQL=0 ) have for us? 只使用存储过程执行,当然在Java代码中使用Prepared Statements, prepareSQL=3 (或prepareSQL=0 )对我们有多大影响? In other words: on every website I find people say "Never use prepareSQL=0 in production environments", is that also applicable to this situation? 换句话说:在每个网站上我都会发现人们说“永远不要在生产环境中使用prepareSQL=0 ”,这也适用于这种情况吗?

  2. If prepareSQL=0 is not a recommended solution, a security issue, etc., we should maybe look for another driver. 如果prepareSQL=0不是推荐的解决方案,安全问题等,我们应该寻找另一个驱动程序。 jTDS has not been updated the past 2 years and Microsoft has a driver for JDBC 4.0. jTDS在过去的两年里没有更新,微软有一个JDBC 4.0的驱动程序。 I can't find any benchmarks or comparisons between jTDS and Microsoft's JDBC 4.0 driver though. 我找不到jTDS和微软的JDBC 4.0驱动程序之间的任何基准或比较。 With Microsoft's 2.0 and 3.0 drivers, the general opinion seemed to be that jTDS is faster, better, more efficient. 使用Microsoft的2.0和3.0驱动程序,一般意见似乎是jTDS更快,更好,更高效。 Is that still the case with JDBC 4.0 or has Microsoft passed its competitor in this? JDBC 4.0仍然如此,或者微软是否通过了它的竞争对手?

when prepareSQL is not equal to 0 jTDS add exactly one level on nesting. 当prepareSQL不等于0时,jTDS在嵌套时只添加一个级别。 Consider follow procedure: 考虑以下程序:

CREATE PROCEDURE F @v int
AS
BEGIN
    select @v = @v - 1
    IF @v = 0 SELECT @v
    ELSE EXEC F @v
END

And java code that use it: 和使用它的java代码:

 Connection connection = DriverManager.getConnection("jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433/xxx;prepareSQL=0");
 PreparedStatement statement = connection.prepareStatement("EXEC F ?");
 statement.setInt(1, 32);
 statement.execute();

If you set prepareSQL to value other than 0 it will fail with "Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)". 如果将prepareSQL设置为0以外的值,则会因“超出最大存储过程,函数,触发器或视图嵌套级别(限制32)”而失败。 You need to find why your code use so much nesting? 您需要找到为什么您的代码使用如此多的嵌套? By prepareSQL=0 you are preventing mssql to use stamements and those forcing to parse SQL on each executing. 通过prepareSQL = 0,你阻止mssql使用stamements和那些强制在每次执行时解析SQL。 It is not a big problem if statement execution time is much more that statement complation time (EG if stored procedyre executes 10 secondse it is not a problem if compilation took 10ms more). 如果语句执行时间远远超过语句编译时间(EG,如果存储过程执行10秒,那么如果编译花费10ms则不是问题),这不是一个大问题。 Changing driver won't help because you will have same issues. 更改驱动程序无济于事,因为您将遇到同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM