• 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

Performance of fomatting string : Java vs Database.

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a String which needs be sent to a stored procedure. Then this string is inserted in the database through the stored procedure. But the string needs to be formatted (say date formatting).

This formatting can be done either in the java program which later calls the stored procedure or in the stored procedure itself. Which way gives better performance?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't worry about the performance of this, but rather the overall design. Formatting data is really not something that should be done in the DB, or for which DBs are well suited.
 
Ritesh Srivastava
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Yes I too agree that database should not be doing formatting. But I am still wondering which approach would be faster.
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ritesh Srivastava:
But I am still wondering which approach would be faster.


It depends. You would have to try it out to be sure.

I second Ulf on the performance not being the driving factor here. It is not likely to be the bottleneck of your application.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the previous posters. Even if they wanted to answer they couldn't as it depends on too many factors. For example does the database run on a more powerful machine than the jvm or vice versa.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A somewhat unrelated side issue is that JDBC is a string-based API anyway. Any data will be sent to the database as a string, not as (e.g.) a date. So if the formatting were done in the DB, then the date would be formatted to a string by JDBC, then sent to the DB, and then be re-formatted according to your rules (and then be parsed and stored by the DB in its own format, whatever that may be). So just based on that I'd guess that doing the formatting in Java has a chance of being faster.
 
Arthur, where are your pants? Check under this tiny ad.
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