你好有用的朋友,
我们在这里遇到了一个问题,我无法弄清楚它为什么会表现出来.希望你能帮助我.
给出TSQL中的以下两个(简化的)存储过程(SQL Server 2008R2)
create procedure [datetransaction1]
as
begin
begin try
begin transaction
declare @a datetime
exec datetransaction2 '2013-02-02 22:21', @a output
select @a
exec datetransaction2 '2013-020222:22', @a output
select @a
exec datetransaction2 '2013-02-02 22:23', @a output
select @a
commit transaction
end try
begin catch
print 'Catch'
end catch
end
Run Code Online (Sandbox Code Playgroud)
和
create procedure [dbo].[datetransaction2] @text nvarchar(100), @res datetime OUTPUT
AS
BEGIN
BEGIN TRY
if (LEN(@text) = 16) SET @text = replace(@text, ' ', 'T') + ':00.000'
else if (LEN(@text) …
Run Code Online (Sandbox Code Playgroud) 我今天在SQL Server(2008R2和2012)中遇到了一个非常奇怪的问题.我正在尝试使用串联和select
语句来构建字符串.
我找到了解决方法,但我真的很想了解这里发生了什么以及为什么它没有给我预期的结果.有人可以向我解释一下吗?
http://sqlfiddle.com/#!6/7438a/1
根据要求,这里的代码也是:
-- base table
create table bla (
[id] int identity(1,1) primary key,
[priority] int,
[msg] nvarchar(max),
[autofix] bit
)
-- table without primary key on id column
create table bla2 (
[id] int identity(1,1),
[priority] int,
[msg] nvarchar(max),
[autofix] bit
)
-- table with nvarchar(1000) instead of max
create table bla3 (
[id] int identity(1,1) primary key,
[priority] int,
[msg] nvarchar(1000),
[autofix] bit
)
-- fill the three tables with the same values …
Run Code Online (Sandbox Code Playgroud) 情况
我有一个(Tomcat)Java Web应用程序,使用jTDS连接到MSSQL 2008数据库.此Java应用程序使用用户输入执行99%的MSSQL存储过程.
问题
jTDS驱动程序有时会(在应用程序的不同位置)回复错误:
超出最大存储过程,函数,触发器或视图嵌套级别(限制32).
我们可以通过添加prepareSQL=0
到jTDS连接字符串来避免这种情况.然后错误随处可见,但是除了所有其他值之外prepareSQL
,错误仍然存在.我不知道jTDS添加了多少存储过程嵌套级别,但显然它对我们的应用来说太多了.
问题
只使用存储过程来执行,当然在Java代码中使用Prepared Statements,对我们有多大的影响prepareSQL=3
(或prepareSQL=0
)?换句话说:在每个网站上我都会发现人们说"从不prepareSQL=0
在生产环境中使用",那是否也适用于这种情况?
如果prepareSQL=0
不是推荐的解决方案,安全问题等,我们应该寻找另一个驱动程序.jTDS在过去的两年里没有更新,微软有一个JDBC 4.0的驱动程序.我找不到jTDS和微软的JDBC 4.0驱动程序之间的任何基准或比较.使用Microsoft的2.0和3.0驱动程序,一般意见似乎是jTDS更快,更好,更高效.JDBC 4.0仍然如此,或者微软是否通过了它的竞争对手?
我正在尝试通过GMail发送电子邮件(实际上是Google Apps).这适用于普通消息,但当然我必须测试极端情况.
现在我正在尝试发送没有正文的消息,我收到一条奇怪的错误消息.因为我想消除代码中的错误,我想知道我做错了什么,或者我正在使用的库中是否有错误.
HtmlEmail currentMessage = new HtmlEmail();
currentMessage.setSSL(true);
currentMessage.setSslSmtpPort(465);
currentMessage.setHostName("smtp.gmail.com");
currentMessage.setAuthentication("abc@gmail.com", "secret");
/** rs is a ResultSet from database **/
if(rs.getString("mailFrom") != null && !rs.getString("mailFrom").isEmpty())
currentMessage.setFrom(rs.getString("mailFrom"));
else
currentMessage.setFrom("abc@gmail.com");
currentMessage.setTo(this.convertRecipientStringToArray(rs.getString("mailTo")));
currentMessage.setCc(this.convertRecipientStringToArray(rs.getString("mailCC")));
currentMessage.setBcc(this.convertRecipientStringToArray(rs.getString("mailBC")));
currentMessage.setSubject(rs.getString("mailSubject"));
if(rs.getString("mailBody") != null && !rs.getString("mailBody").isEmpty())
currentMessage.setTextMsg(rs.getString("mailBody"));
if(rs.getString("mailHtmlBody") != null && !rs.getString("mailHtmlBody").isEmpty())
currentMessage.setHtmlMsg(rs.getString("mailHtmlBody"));
if(rs.getString("mailReplyTo") != null && !rs.getString("mailReplyTo").isEmpty())
currentMessage.addReplyTo(rs.getString("mailReplyTo"));
else
currentMessage.addReplyTo("def@gmail.com");
currentMessage.send();
Run Code Online (Sandbox Code Playgroud)
此代码适用于"普通"电子邮件:具有有效的正文,主题,收件人等.
当数据库中的mailBody 和 mailHtmlBody都为NULL或为空时,我收到以下错误:
将电子邮件发送到以下服务器失败:smtp.gmail.com:25
完整错误日志(自己的日志格式)/ stacktrace:
[CRITICAL] 2012-12-19 17:08:00 [CET] - Exception occurred in function com.mypackage.mymailobject.outgoing_sendMails: Sending the email to the …
Run Code Online (Sandbox Code Playgroud)