This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes alternate to DB connection/xml Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "alternate to DB connection/xml" Watch "alternate to DB connection/xml" New topic
Author

alternate to DB connection/xml

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 77
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

Joined: May 14, 2008
Posts: 5536

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


JBoss In Action
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 77


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

Joined: Dec 20, 2006
Posts: 2343

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?


OCUP UML fundamental
ITIL foundation
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: alternate to DB connection/xml
 
Similar Threads
What to do after SCWCD
Help please!!! Is there a method for closing sessions java-side?
connection pooling - sort by most recently used?
Newbie Conn Pool question
which xml parser suitable 4 this?