|
||
|
|||
|
Hi!
I am working in web application project, I have a doubt,when should use String and String Buffer, I know the concept String in immutable and StringBuffer is muttable,So every time i am assign the value into the String its taking separate memory,.... My doubt is I have a executeQuerymanager Class,...So when i want to execute the query so i jst put the query in String and call the executeQuerymanager Class,So in my Class if i want to execute two the String So i am Using Same String variable and Calling the Class,..... So shall i make it StringBuffer instead of String?..... Hope u underStand my doubt,... eg: Java Code
String query = ""; ResultSet rs = null; query = "select * from XXX"; rs = executeQueryManager(query); query = "select * from YYY"; rs = = executeQueryManager(query); Thanks, kalees
|
|
|||
|
Thanks,
But i am having different querys in my action class,each time i calling queryManager,i am jst passing the query,.... eg : Java Code
query ="select userName,userPass from userTable";
rs = queryManager(query);
query = "select price from priceTable;
rs = queryManager(query);
|
|
||||
|
I meant you should have a list of queries.
Java Code
private static final String QUERY1 = "select username,password,email from userstable"; private static final String QUERY2 = "select * from someothertable"; private static final String QUERY3 = "select * from userstable WHERE username=?"; // Json |
|
|||
|
Yes!
I am doing web application banking project,in struts frame work, in my action class i am getting query result from different tables,so my QueryManager will return the query result set,So my doubt is, Java Code
private static final String QUERY1 = "select username,password,email from userstable";
private static final String QUERY2 = "select * from someothertable";
private static final String QUERY3 = "select * from userstable WHERE username=?";
will it be create more object then it takes more memory right? So if i use StringBuffer then it will use the same memory right?..... What is the benefit of creating different string obj for different query?..... |
|
||||
|
When you declare all your queries as statics they will of course take up memory like that but you will have a reference to the same strings so it will be dead quick.
When you use the StringBuffer you will create a lot of strings anyways and they all get stored into the string pool anyways so in effect they will take up memory. Using a stringbuilder or even stringbuffer which is slower will take more time in the long end. In my opinion there's no reason to use a StringBuilder if you know that the strings will be the exactly same every time. Otherwise you can create a properties file in your web-inf/classes folder called databaseQueries.properties and load that into memory and just get the query you need from it. The amount of memory taken up by your queries will be nothing compared to the objects you will be putting on the session anyways I believe. // Json |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| error cannot find symbol-constructor Person(java.lang.String,java.lang.String,Date) | ss7 | What's Wrong With My Code? | 2 | 03-11-2009 10:28 AM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? |