• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

OutOfMemoryExcepiton!

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have made one swing application where i make a connection to Oracle database and then read
some 2000+ blob values and write it on different files on my hard-disk

now while the code is reading the blob data and then writing the blob data on the the file
, after some transaction i get this exception



the algorithm goes this way
(1)Take the db details and database table from where the blob has to be read from user(user enters the data in JTextFeild)
(2)Validate above information for blank or null values
(3)If validation is successful then move ahead.
(4)pass the validated information to a class ConnectionHelper , this class basically has api's to connect to database and then read
blob from db and write it in file.
(5) code to obtain connection is :

here oracle_connection is a static object of type Connection in ConnectionHelper class and dbDetails is a DTO which contains all database information.
(6)Code that reads Blob and writes in to file :

(7)Above method reads Blob data from db against an id which is passed as an argument,
then it will take the connection , now if connection is null or it is closed new connection will be passed
otherwise the existing connectin is returned (i believe i have messed up here!)
(8)and this method is called for more than 2000 times, and after a while when many files are written successfully i get the above
OutOfMemoryException.

please help

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could it be that a particular blob value in a row in your database is too big?
Can you check your database table to see what is the size of the largest blob.

You can always increase the heap size by using -Xmx option.
java -Xmx256m MyClass
 
mahavir swami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
exactly

there was one file , size was really big
it was 74673925 when i debug on blob.length()

so it breaking on new byte[74673925]

so you cannot create a new byte array with size 74673925??

 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either increase the heap size.

OR

Try reading the blob data in chunks. See the java.sq.blob API, eg: getBytes method.

By the way, your program seems to be creating a empty buffer simply based on length of the blob, but not reading any data from blob itself.
 
mahavir swami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually i am reading from istream

and then from stream i am reading into buffer
and then writing the buffer in to outputStream

but you are rite, i should have used getBytes from blob and then write the
binary array on ouputStream


thanks a lot James!


 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic