jdbc连接数据库执行存储过程tomcat outOfMemory
我用jdbc连接sqlserver 2008数据库 执行 procedure 增量从另一个库中同步数据:
sqlserver procedure(从另一个数据库增量同步数据的存储过程)中加了一些print 语句,这些print影响的tomcat内存,没有的这些语句的时候,tomcat内存消耗300M左右,但是加了print之后tomcat内存消耗增加到了1800M,
数据量:需要做增量同步的表数据为34万条,被同步的表数据也为34万(只多不少),每一次游标循环都有三个print语句
为什么这些procedure中的print语句为消耗如此多的tomcat内存呢?
以下是我的过程
create PROCEDURE loadDataForStock
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @store VARCHAR(20)
Declare @storeId Int
Declare @sku VARCHAR(20)
Declare @skuId Int
Declare @qty Int
Declare @stockSku VARCHAR(20)
Declare @stockStore VARCHAR(20)
Declare cStock cursor For
SELECT store, sku, qty FROM [TACCStock]
OPEN cStock
Fetch Next From cStock Into @store, @sku,@qty
While @@Fetch_Status = 0 Begin
SELECT @storeId = id FROM Tbl_Store WHERE store_no = @store
SELECT @skuId = id FROM Tbl_Sku WHERE sku_code = @sku
SELECT @stockSku = [sku_id] , @stockStore = [store_id]
FROM Tbl_Stock WHERE sku_id = @skuId AND store_id = @storeId AND qty <> @qty
IF(@stockSku IS NOT NULL AND @stockStore IS NOT NULL)
BEGIN
Update [Tbl_Stock] SET qty = @qty
WHERE sku_id = @stockSku AND store_id = @stockStore
END
--print @qty
--pirnt @sku
--print @stockStore
Declare @existed int
SELECT @existed=count(*) FROM [Tbl_Stock] WHERE sku_id = @skuId AND store_id = @storeId
IF(@existed=0)
BEGIN
INSERT INTO [dbo].[Tbl_Stock]
([version]
,[qty]
,[sku_id]
,[store_id])
VALUES(0, @qty, @skuId, @storeId)
END
Fetch Next From cStock Into @store, @sku,@qty
End -- End of Fetch
Close cStock
Deallocate cStock
END
GO
这是我的过程
-----------------------------------------------------------------------------------
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "lab_user", "root");
CallableStatement proc = null;
System.out.println("start:"+new Date());
proc = conn.prepareCall("{call loadDataForStock}");
proc.execute();
这是java调用code
---------------------------------------------------------------------------