• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alternate to DB connection/xml

 
Edmund Castermund
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
 
Edmund Castermund
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic