• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryExcepiton!

 
mahavir swami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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

 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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!


 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!