Reputation: 401
I have ResultSet of 100k records with each record has 5 cell 2 of them are of int data type and 3 are of Varchar (100) data type
my question is how the memory is allocated to resultset for these data types when a query is executed from a java program
specially to varchar data type is all the varchar(100) cells have same memory of 100 chars or it depends on the data each varchar(100) cell contains
for example say I have the following record with two cell on varchar(100)
------------------------ | "abc" | | "pqrstuv" | ------------------------
is memory size here 10 chars or 200 chars?
regards
Upvotes: 2
Views: 1419
Reputation: 53694
the "varchar" type is for variable length strings. thus, your strings will only take the amount of space as the number of characters actually in the string (so 10 chars in your example). if you defined those fields as just "char" (fixed length), then they would take up 100 characters each.
Upvotes: 1
Reputation: 533492
Most JDBC drivers support paging of result sets. This means only a portion of results are loaded at a time. The amount of memory used internal is unlikely to matter because it will only ever be a sub-set of the data. If you keep all the records, the amount of data used is more important. When you retain a String it will use 1-2 bytes per character (plus some overhead) depending on your JVM.
Either way, unless you have a mobile device the memory used is likely to be very small compared to the memory you have.
Upvotes: 0