• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

alternate to DB connection/xml

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm writing a java app that connects to a DB on a server I have on my home network. I want to be able to dump the data as xml, and use that when I have my laptop and no db connection is available....I've been writing some code like so:



but it takes a long time for the db connection attempt to time out, and sometimes (in eclipse) the app just bombs before it gets to the else block.

What's the best way to handle this, meaning attempt to connect to the db, look for an xml file if it's unavailable.
thanks,
bp
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if this help: http://www.codase.com/java/java/sql/DriverManager.html#setLoginTimeout%28int%29
 
Edmund Castermund
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Johnson wrote:See if this help: http://www.codase.com/java/java/sql/DriverManager.html#setLoginTimeout%28int%29



thanks, I'll try that tonight...is that a standard thing; try to connect to a db, and connect to another source if it times out? Is it bad design?
bp
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Edmund Castermund wrote:...is that a standard thing; try to connect to a db, and connect to another source if it times out? Is it bad design?

It is not standard, but as per your requirements. Lots of applications fail when their database is not available.
It is not bad design. You require it. Your proposal to connect to the second source if connecting to the first one fails is ok.

However, if you are going to call getConnection each time you want to write something, that will be:
- a performance issue: you will hit the timeout every time
- a data consistency issue: you have saved a part to XML, then you plug in your network cable. Next data storage will happen to the database, because getConnection succeeds.

Isn't it better to check and select source once at program start, and continue using the data source until program ends?
 
reply
    Bookmark Topic Watch Topic
  • New Topic