在tomcat中,数据库连接在部分执行之间被关闭,得到java.net.Connection:拒绝连接。异常在任何操作上都不一致,它在不同的时间间隔之间抛出。谁能帮忙吗?

谢谢

最佳答案

如果OBJECT_ID('sysGenerateInsert','P')不为空
开始
    DROP PROC sysGenerateInsert
    PRINT'sysGenerateInsert SP成功删除'
结束


创建PROC sysGenerateInsert(@TblName varchar(128))

开始
    -------------------------------------------------- ---------------
    -目的:为给定表生成INSERT语句
    -*多行插入
    -*复制生成的脚本并删除最后一个逗号
    -并执行
    -
    -用法:EXEC sysGenerateInsert'TableName'
    -
    -创建者:Guruprasad发表于:2010年1月3日
    -------------------------------------------------- ---------------
    创建表#ColumnMetaData(
        ID INT IDENTITY(1,1),
        IsChar INT,
        ColName VARCHAR(128)
    )

IF NOT EXISTS (SELECT *
                 FROM INFORMATION_SCHEMA.COLUMNS
                WHERE  TABLE_NAME = @TblName)
BEGIN
    RAISERROR('No columns found for table %s or Table not exist', 16,-1, @TblName)
    RETURN
END

INSERT  #ColumnMetaData (IsChar, ColName)
SELECT CASE WHEN DATA_TYPE LIKE '%char%'
            THEN 1
            ELSE 0 END IsChar,
       COLUMN_NAME     ColName
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_NAME = @TblName
ORDER BY ORDINAL_POSITION

DECLARE @InsertIntoStmt VARCHAR(MAX),
        @InsertIntoData VARCHAR(MAX)

SELECT @InsertIntoStmt = 'SELECT '' INSERT INTO ' + @TblName + ' ( '
SELECT @InsertIntoData = 'SELECT ''(''+'

SELECT  @InsertIntoStmt = @InsertIntoStmt + ColName + ','
FROM    #ColumnMetaData

SELECT @InsertIntoData =    @InsertIntoData
        + ' CASE WHEN ' + ColName + ' IS NULL '
        +   ' THEN ''NULL'' '
        +   ' ELSE '
        +     CASE WHEN IsChar = 1
                   THEN  ''''''''' + ' + ColName + ' + '''''''''
                   ELSE 'CONVERT(VARCHAR(20),' + ColName + ')'
              END
        + ' END + '','' + '
FROM    #ColumnMetaData

SELECT @InsertIntoStmt = LEFT(@InsertIntoStmt,LEN(@InsertIntoStmt)-1) + ' )  VALUES '''
SELECT @InsertIntoData = LEFT(@InsertIntoData,LEN(@InsertIntoData)-8) + ' + ''),'' FROM ' + @tblName

EXEC (@InsertIntoStmt + ' UNION ALL ' + @InsertIntoData)

DROP TABLE #ColumnMetaData


结束


PRINT'sysGenerateInsert SP已成功创建'

关于database - 在tomcat中,在部分执行之间关闭数据库连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31348198/

10-14 04:30