Private SQTbl As SQL
Private wb As PoiWorkbook
Private ws As PoiSheet
Private row As PoiRow
Dim SenderFilter As Object = SQTbl.ExecQueryAsync("SQL", "SELECT a.* from CNT_GET_MONTHLY_SLS(2015,5) a", Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, RS As ResultSet)
If Success Then
Private RowNo = 6,i = 1 As Int
If wb.IsInitialized = False Then
wb.InitializeExisting(File.DirApp,"CntRcpMonthlySls.xlsx","")
ws = wb.GetSheet(0)
End If
Do While RS.NextRow
row = ws.CreateRow(RowNo)
row.CreateCellString(0,RS.GetString("REGION"))
row.CreateCellString(1,RS.GetString("AREA"))
row.CreateCellString(2,RS.GetString("CTY"))
row.CreateCellString(3,RS.GetString("KOORD"))
row.CreateCellString(4,RS.GetString("DEPT"))
row.CreateCellString(5,RS.GetString("CD"))
row.CreateCellString(6,RS.GetString("COUNTER"))
row.CreateCellString(7,RS.GetString("SB_GRP"))
row.CreateCellString(8,RS.GetString("GRP"))
row.CreateCellString(9,RS.GetString("PRD_YR"))
row.CreateCellString(10,RS.GetString("ART"))
row.CreateCellString(11,RS.GetString("CL"))
row.CreateCellNumeric(12,RS.GetInt("Y1M1"))
row.CreateCellNumeric(13,RS.GetInt("Y1M2"))
row.CreateCellNumeric(14,RS.GetInt("Y1M3"))
row.CreateCellNumeric(15,RS.GetInt("Y1M4"))
row.CreateCellNumeric(16,RS.GetInt("Y1M5"))
row.CreateCellNumeric(17,RS.GetInt("Y1M6"))
row.CreateCellNumeric(18,RS.GetInt("Y1M7"))
row.CreateCellNumeric(19,RS.GetInt("Y1M8"))
row.CreateCellNumeric(20,RS.GetInt("Y1M9"))
row.CreateCellNumeric(21,RS.GetInt("Y1M10"))
row.CreateCellNumeric(22,RS.GetInt("Y1M11"))
row.CreateCellNumeric(23,RS.GetInt("Y1M12"))
row.CreateCellNumeric(24,RS.GetInt("Y2M1"))
row.CreateCellNumeric(25,RS.GetInt("Y2M2"))
row.CreateCellNumeric(26,RS.GetInt("Y2M3"))
row.CreateCellNumeric(27,RS.GetInt("Y2M4"))
row.CreateCellNumeric(28,RS.GetInt("Y2M5"))
row.CreateCellNumeric(29,RS.GetInt("Y2M6"))
row.CreateCellNumeric(30,RS.GetInt("Y2M7"))
row.CreateCellNumeric(31,RS.GetInt("Y2M8"))
row.CreateCellNumeric(32,RS.GetInt("Y2M9"))
row.CreateCellNumeric(33,RS.GetInt("Y2M10"))
row.CreateCellNumeric(34,RS.GetInt("Y2M11"))
row.CreateCellNumeric(35,RS.GetInt("Y2M12"))
row.CreateCellNumeric(36,RS.GetInt("Y3M1"))
row.CreateCellNumeric(37,RS.GetInt("Y3M2"))
row.CreateCellNumeric(38,RS.GetInt("Y3M3"))
row.CreateCellNumeric(39,RS.GetInt("Y3M4"))
row.CreateCellNumeric(40,RS.GetInt("Y3M5"))
row.CreateCellNumeric(41,RS.GetInt("Y3M6"))
row.CreateCellNumeric(42,RS.GetInt("Y3M7"))
row.CreateCellNumeric(43,RS.GetInt("Y3M8"))
row.CreateCellNumeric(44,RS.GetInt("Y3M9"))
row.CreateCellNumeric(45,RS.GetInt("Y3M10"))
row.CreateCellNumeric(46,RS.GetInt("Y3M11"))
row.CreateCellNumeric(47,RS.GetInt("Y3M12"))
row.CreateCellNumeric(48,RS.GetInt("TTL"))
RowNo = RowNo + 1
i = i+1
Loop
RS.Close
Else
Log(LastException)
End If
'Total
row = ws.CreateRow(RowNo)
row.CreateCellString(0,"")
row.CreateCellString(1,"")
row.CreateCellString(2,"")
row.CreateCellString(3,"")
row.CreateCellString(4,"")
row.CreateCellString(5,"")
row.CreateCellString(6,"")
row.CreateCellString(7,"")
row.CreateCellString(8,"")
row.CreateCellString(9,"")
row.CreateCellString(10,"")
row.CreateCellString(11,"")
row.CreateCellFormula(12,$"sum($M7:$M${RowNo})"$)
row.CreateCellFormula(13,$"sum($N7:$N${RowNo})"$)
row.CreateCellFormula(14,$"sum($O7:$O${RowNo})"$)
row.CreateCellFormula(15,$"sum($P7:$P${RowNo})"$)
row.CreateCellFormula(16,$"sum($Q7:$Q${RowNo})"$)
row.CreateCellFormula(17,$"sum($R7:$R${RowNo})"$)
row.CreateCellFormula(18,$"sum($S7:$S${RowNo})"$)
row.CreateCellFormula(19,$"sum($T7:$T${RowNo})"$)
row.CreateCellFormula(20,$"sum($U7:$U${RowNo})"$)
row.CreateCellFormula(21,$"sum($V7:$V${RowNo})"$)
row.CreateCellFormula(22,$"sum($W7:$W${RowNo})"$)
row.CreateCellFormula(23,$"sum($X7:$X${RowNo})"$)
row.CreateCellFormula(24,$"sum($Y7:$Y${RowNo})"$)
row.CreateCellFormula(25,$"sum($Z7:$Z${RowNo})"$)
row.CreateCellFormula(26,$"sum($AA7:$AA${RowNo})"$)
row.CreateCellFormula(27,$"sum($AB7:$AB${RowNo})"$)
row.CreateCellFormula(28,$"sum($AC7:$AC${RowNo})"$)
row.CreateCellFormula(29,$"sum($AD7:$AD${RowNo})"$)
row.CreateCellFormula(30,$"sum($AE7:$AE${RowNo})"$)
row.CreateCellFormula(31,$"sum($AF7:$AF${RowNo})"$)
row.CreateCellFormula(32,$"sum($AG7:$AG${RowNo})"$)
row.CreateCellFormula(33,$"sum($AH7:$AH${RowNo})"$)
row.CreateCellFormula(34,$"sum($AI7:$AI${RowNo})"$)
row.CreateCellFormula(35,$"sum($AJ7:$AJ${RowNo})"$)
row.CreateCellFormula(36,$"sum($AK7:$AK${RowNo})"$)
row.CreateCellFormula(37,$"sum($AL7:$AL${RowNo})"$)
row.CreateCellFormula(38,$"sum($AM7:$AM${RowNo})"$)
row.CreateCellFormula(39,$"sum($AN7:$AN${RowNo})"$)
row.CreateCellFormula(40,$"sum($AO7:$AO${RowNo})"$)
row.CreateCellFormula(41,$"sum($AP7:$AP${RowNo})"$)
row.CreateCellFormula(42,$"sum($AQ7:$AQ${RowNo})"$)
row.CreateCellFormula(43,$"sum($AR7:$AR${RowNo})"$)
row.CreateCellFormula(44,$"sum($AS7:$AS${RowNo})"$)
row.CreateCellFormula(45,$"sum($AT7:$AT${RowNo})"$)
row.CreateCellFormula(46,$"sum($AU7:$AU${RowNo})"$)
row.CreateCellFormula(47,$"sum($AV7:$AV${RowNo})"$)
row.CreateCellFormula(48,$"sum($AW7:$AW${RowNo})"$)
Private BorderSum As PoiCellStyle
If BorderSum.IsInitialized = False Then BorderSum.Initialize(wb)
BorderSum.BorderTop = BorderSum.BORDER_DOUBLE
BorderSum.BorderBottom = BorderSum.BORDER_DOUBLE
BorderSum.BorderLeft = BorderSum.BORDER_THIN
BorderSum.BorderRight = BorderSum.BORDER_THIN
For i = 0 To 48
row.GetCell(i).CellStyle = BorderSum
Next
DateTime.DateFormat= "MMddyy"
DateTime.TimeFormat="HHmmss"
Private stDateTime="_" & DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.now) As String
FName = "Rpt" & stDateTime & ".xlsx"
wb.Save(File.DirApp,FName)
fx.ShowExternalDocument(File.GetUri(File.DirApp, FName))
Dim SenderFilter As Object = SQTbl.ExecQueryAsync("SQL", "SELECT a.* from CNT_GET_MONTHLY_SLS(2015,5) a rows 10000", Null)
Sub AppStart (Args() As String)
Dim pw As PoiWorkbook
pw.InitializeNew(True)
Dim sheet As PoiSheet = pw.AddSheet("sheet1", 0)
For RowNumber = 1 To 100000
Dim Row As PoiRow = sheet.CreateRow(RowNumber)
For ColNumber = 1 To 50
Row.CreateCellString(ColNumber, "Col: " & ColNumber)
Next
If RowNumber Mod 1000 = 0 Then Log(RowNumber)
Next
File.Delete(File.DirApp, "1.xlsx")
pw.Save(File.DirApp, "1.xlsx")
pw.Close
ExitApplication
End Sub
This program creates a sheet with 100,000 rows and 50 columns:
Works fine here. Do you get any error?B4X:Sub AppStart (Args() As String) Dim pw As PoiWorkbook pw.InitializeNew(True) Dim sheet As PoiSheet = pw.AddSheet("sheet1", 0) For RowNumber = 1 To 100000 Dim Row As PoiRow = sheet.CreateRow(RowNumber) For ColNumber = 1 To 50 Row.CreateCellString(ColNumber, "Col: " & ColNumber) Next If RowNumber Mod 1000 = 0 Then Log(RowNumber) Next File.Delete(File.DirApp, "1.xlsx") pw.Save(File.DirApp, "1.xlsx") pw.Close ExitApplication End Sub
pw.Close
We're talking about Java here and garbage collection. Java's garbage collection can be "lazy" and not reclaim the memory unless required by the app itself (or after some long inactivity). It does not really mean it's not available (for the app). Yes, for other applications in the system, the memory is unavailable.But apparently not, RAM only released after app closed
This idea has crossed my mind, but the problem remain.Looks like the setFetchSize method applies to both the Statement and the ResultSet objects of JDBC (for usage see here). This method and the Statement object are not exposed by jSQL, so some JavaObject or Reflection code would be needed to get to this method/object.
Optionally, you could use Firebird's ROWS <m> [TO <n>] clause (or if older version is used the [FIRST <m>] [SKIP <n>] clause) of the SELECT statement to iterate through a batch of records at a time from the Firebird database.
Edit:
Firebase documentation links:
FIRST... (http://www.firebirdtest.com/file/do...langref25-en/html/fblangref25-dml-select.html)
ROWS... (http://www.firebirdtest.com/file/do...5-dml-select.html#fblangref25-dml-select-rows)
See this (https://poi.apache.org/spreadsheet/quick-guide.html#FileInputStream), but I don't know how to apply it to jPOI.More row created with jPOI, more RAM usage, so soon / later, with big data, RAM will not enough
Dim SenderFilter As Object = SQTbl.ExecQueryAsync("SQL", "SELECT a.* from CNT_GET_MONTHLY_SLS(2015,5) a rows 5000", Null)
Do While RS.NextRow
Log(RowNo)
.....
.....
loop
I think, only Erel can apply thisSee this (https://poi.apache.org/spreadsheet/quick-guide.html#FileInputStream), but I don't know how to apply it to jPOI.
I have already use the latest driver version.You are correct that the first step is to identify which part if the problematic one. It seems like the problem is in the JDBC driver.
Make some tests.
Make sure that you are using the latest version of their driver.
Private FirstRow,RowsFetched As Int
SourceFile = "1.xlsx"
FirstRow = 6
Sub Test
for i = 1 to 1000
FName = GenerateUniqFileName("Tmp")
StartRow = (i-1)*1000
EndRow = i*1000
FirstRow = 6
SqSt = "SELECT a.* from LARGE_DT a rows " & StartRow & " to " & EndRow
RowsFetched = RetriveDataSaveToExcel(FirstRow,SqlSt,SourceFile,FName)
If FirstRow <> RowsFetched Then
Log("rowno : " & FirstRow )
Log("RowsFetched : " & RowsFetched)
FirstRow = RowsFetched
SourceFile = FName
P.Progress = i/MaxRowsFetched
Sleep(50)
Else
P.Progress = 1
i = 2000
End If
Next
EndSub
Sub RetriveDataSaveToExcel(FirstRow,SqlSt,SourceFile,FName) As int
Private wb As PoiWorkbook
Private ws As PoiSheet
Private row As PoiRow
Private RS As ResultSet
wb.InitializeExisting(File.DirApp,SourceFile,"")
ws = wb.GetSheet(0)
RS = SQTbl.ExecQuery(SqSt)
Do While RS.NextRow
FirstRow = ws.CreateRow(FirstRow )
....
FirstRow = FirstRow + 1
Loop
wb.Save(File.DirApp,FName)
wb.Close
Return FirstRow
End Sub
Try to write the data to a new workbook instead of loading an existing one.
Private Sub SetXLBorder(wb As PoiWorkbook, xlrow As PoiRow, NoOfCol As Short)
Private XLBorderS As PoiCellStyle
XLBorderS.Initialize(wb)
XLBorderS.BorderBottom = XLBorderS.BORDER_HAIR
XLBorderS.BorderRight = XLBorderS.BORDER_THIN
For i = 0 To NoOfCol - 1
xlrow.GetCell(i).CellStyle = XLBorderS
Next
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?