Eclipse, Run Configurations
In our last episode, I managed to connect to the database. Now what I want to do is extract data from the database and write it out as standalone XML files, one XML file per item.
I’m not going to go through every step of the process since I’m not really writing a tutorial here, just covering the stuff I’m doing so I’ve got a log of any problems I run into, so I can refer to this the next time. Getting started doing Java development in Eclipse is something that’s generally covered pretty well elsewhere.
One difference between Eclipse and Visual Studio took a little figuring out is that with Visual Studio, you say Start and it starts the active project, where Eclipse doesn’t have an active project concept. You can say Run last launched, or you can select a configuration to run. If you’ve not run your app yet, then you need to create a configuration before you can run it (by selecting Run…, clicking Java Application in the list, clicking New, and picking the class to start).
Where this is an improvement over Visual Studio is when you’re running the same binary in multiple contexts. The most obvious place where you’d do this is unit testing – you can create a run configuration for Java Application, one for JUnit, and run either one without needing to change any settings.
Anyway this example was easy to modify into something I could use to read the cs_Posts table out of Community Server. The only changes were to the connection string, driver class name, and the SQL query text.
Next step: Writing the records out as XML.
August 27th, 2005 at 6:54 pm
That JDBC example is a good example of how not to gracefully handle errors with JDBC. Luckily for you it’s just a one-off tool you’re doing, but if it were production quality stuff, you would want to close things in a finally {} block outside the try/catch. Also, you would want each .close() wrapped in its own try/catch so if one close fails, the other one can still be attempted. JDBC is a pain that way and is often used as an example of why checked exceptions are no fun.