background preloader

Java

Facebook Twitter

How to Close JDBC Resources Properly – Every Time | The Shine Technologies Blog. In a Java program, we sometimes need to make sure we close a resource after we’ve finished using it. Common examples are files, Hibernate Sessions, JDBC Connections, Statements and ResultSets. The database-related ones are particular important – if we don’t close them, we can be left with unclosed connections to the database. This means that we could eventually run out of connections. Sure, these objects are supposed to close their underlying resources when they’re garbage collected, but sometimes they don’t get a chance to (for example, if the JVM exits suddenly) and sometimes they don’t do it even though they’re supposed to (some dodgy JDBC drivers can do this – I once used one that would leave the underlying database connection open if you didn’t close the ResultSet – even if you closed the Connection object).

Of course, I’m probably not telling you anything new here. And you’ll probably tell me that all you need to do is provide a ‘finally’ block that closes the resource. Like this: Three Minutes to a Web Service. Leading-Edge JavaThree Minutes to a Web ServiceWrite a Web service in 15 lines of code with JAX-RPC 2.0 Early Accessby Frank SommersMay 23, 2005 Page 1 of 3 >> Summary A key aim of JAX-RPC 2.0 (JSR 224) is to simplify Java Web service development. Currently in early draft review stage in the JCP, an early access JAX-RPC 2.0 reference implementation is available from the Java Web services community site on java.net. This article provides a brief preview of writing a JAX-RPC 2.0-based Web service with that reference implementation, and highlights how Java annotations simplify Web service development. Annotations are a relatively new Java language feature that debuted in the JDK 1.5 [see Resources].

A key benefit of annotations is that they provide a kind of shorthand when programming. JAX-RPC 2.0 prescribes a set of annotations that, when passed to the JDK's annotation processing utility, apt [see Resources], generate much of a Web service's code automatically. Simplified SnmpUtility class based upon SNMP4J. The Java(TM) Web Services Tutorial.

Best practices to improve performance in JDBC. Best practices to improve performance in JDBC This topic illustrates the best practices to improve performance in JDBC with the following sections: Overview of JDBC JDBC defines how a Java program can communicate with a database. This section focuses mainly on JDBC 2.0 API. JDBC architecture defines different layers to work with any database and java, they are JDBC API interfaces and classes which are at top most layer( to work with java ), a driver which is at middle layer (implements the JDBC API interfaces that maps java to database specific language) and a database which is at the bottom (to store physical data). JDBC API provides interfaces and classes to work with databases. The following are the basic steps to write a JDBC program 1. 2. 3. 4. 5. 6. 7. Note1: Your JDBC driver should be fully compatible with JDBC 2.0 features in order to use some of the suggestions mentioned in this section.

Note2: This Section assumes that reader has some basic knowledge of JDBC. Choosing right Driver.