java - How to test if a PreparedStatement is going to run out of memory -



java - How to test if a PreparedStatement is going to run out of memory -

so have java code using jdbc insert info postgresql database using prepared statement looks little this:

preparedstatement statement = // prep statement (int value: values) { statement.setint(1, value); statement.addbatch(); } statement.executebatch();

the problem is, i'm hitting exception java.lang.outofmemoryerror: java heap space. i've taken around, can't find on it; how test if statement run out of memory can execute batch. this:

preparedstatement statement = // prep statement (int value: values) { statement.setint(1, value); statement.addbatch(); if (statement.currentsize() + sizeof(int) > statement.mazsize()) { statement.executebatch(); } } statement.executebatch();

thanks help.

there no reliable way find out in advance whether instantiation fail.

however, more point: misusing jdbc batching facility, there solve issue of network roundtrip overhead when inserting many rows. batch sizes of above 100 show diminishing returns , may result in slowdowns.

so, alter batching policy utilize fixed batch size of smallish, double-digit integer.

java postgresql jdbc prepared-statement

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -