The JDBC code is a part of Java decoding, which brings quantitative repetition to the written encoding. In addition, the JDBC code is almost regularly brought about low-level errors. It is not difficult to write good JDBC coding, but it is very painful. The DBUTILS component is a precise and simple component. It doesn't make a complex thing, but only makes a lot of JDBC tasks to make a little easier to developers. Although many persistent frameworks and packages can be used to make data lasting easier, JDBC is still a tool that most Java and Java2 Enterprise (J2EE) developers have survived. Therefore, anything that makes it easier to use JDBC work is good news. DBUTILS can be downloaded for free, it does not rely on any other universal component, but only below these:
Java Development Kit (JDK) 1.2 (or Later) JDBC 2.0 (or Later)
The DBUTILS document is not the best, but it is enough to make your work normally. In the next section, you will see the most useful classes in DBUTILS and some examples of the usage of them. You should be able to easily use these codes and examples, and then you can start using dbutils immediately in your own project. I will focus on two classes (org.apache.commons.dbutils.dbutils and org.quache.commons.dbutils.Queryrunner) and an interface (org.apache.commons.dbutils.ResultSetHandler). I will give you some For examples of their usage, let us go deep into dbutils to take a closer look at what it provides us.
DBUTILS DBUTILS is a class that provides useful methods for making some general work such as shutdown, and loads a JDBC driver. It is static.
The important methods in this class are:
Close: The DBUTILS class provides three overloaded closing methods. These methods check the parameters provided by NULL, if not, they turn off the connection, declaration, and result set. Closequietr: Closequietly This method not only avoids shutting down in connection, declaration, or result set (Resultset) to avoid off, but also hide some SQleeception thrown in the program. If you don't want to capture these anomalies, this is very useful for you. When overloading the Closequietly method, a particularly useful method is Closequiet (CONNECTION CONN, STATEMT, RESULTSET RS) because in most cases, connection, declaration and result set (Resultset) is the three like you want to use. Things, and in the last block you have to close them. Using this method, your last block can only need to call this method. CommitAndClosequietly (Connection CONN): This method is used to submit a connection, then close the connection, and do not throw some SQL anomalies when it is closed when the connection is turned off. LoadDriver (String DriveClassName): This method is loaded and registered with a JDBC driver, and returns true if successful. Using this method, you don't need to capture this exception ClassNotFoundException. Using the loadDrive method, the encoding will become easier to understand, you also get a good Boolean return value, this return value tells you that the driver class has been successfully loaded.
ResultSetHandler