This article illustrates best practices to improve performance of Daffodil DB / One$DB JDBC Driver. This article focuses on how to improve performance of a Daffodil DB / One$DB JDBC application using Statement, PreparedStatemnt, CallableStatement and ResultSet interfaces. Choosing right statement interfaces and right methods according to your SQL query plays a vital role in improving performance of a JDBC Driver. JDBC Overview
JDBC API provides standard set of interfaces to work with databases like Daffodil DB / One$DB, Oracle, Derby etc.
Connection interface encapsulates database connection functionality, Statement interface encapsulates SQL statement representation and execution functionality whereas ResultSet interface encapsulates retrieving data which comes from execution of a SQL query using Statement.
Following are basic steps to write a JDBC program.
1.Import "java.sql" and "javax.sql" packages. (Import "javax.sql", if advanced JDBC feature like XA is to be used)
2.Load Daffodil DB JDBC driver (embedded or network JDBC Driver)
3.Establish connection to database using Connection interface
4.Create a Statement
5.Execute Statement
6.Retrieve results by using ResultSet interface
7.Close Statement and Connection
Choosing right Statement interface:
There are three types of Statement interfaces in JDBC to represent/execute a SQL query-Statement, PreparedStatement and CallableStatement. Statement is used for executing static SQL statement with no input and output parameters; PreparedStatement is used to execute dynamic SQL statement with input parameters whereas CallableStatement is used to execute dynamic SQL with both input and output parameters. One important thing to note about PreparedStatement and CallableStatement is that they can also be used for static SQL statements. However, CallableStatement is mainly meant for stored procedures.