• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Vs Stringbuffer  RSS feed

 
Gaurav Jain
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To write SQL's which way of the following is better and why:

1. String query = "part1 of query"
query+ = "remaining query";

2. StringBuffer query.apend("part1 of query").append("remaining query");
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler replaces String concatenation using + with StringBuffer.append(). If you're going to add up many pieces to make the query, using a StringBuffer directly will gain slight performance (very slight compared to running the query) over code clarity.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better go for Prepared statement instead of formatting the whole query ..
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!