Java JDBC By Travis Mitchell - Scrum-Lords/User-Guides GitHub Wiki
Java JDBC:
Java JDBC is a Java API that is able to access different kinds of tubular data, especial data stored in relational databases. The JDBC is a independent connection between the java language and a range of databases.
Common Databases used:
- MySQL DB
- PostgreSQL DB
- Oracle DB
JDBC Driver Types:
- JDBC-ODBC Bridge Driver
- JDBC-Native API
- JDBC-Net pure Java
- 100% Pure Java
Connecting to Database
Import JDBC Packages:
- import java.sql.*; for regular JDBC programs
- import java.math.*; for Big Decimal and Big Integer support.
Register JDBC Driver:
- Class.forName();
Example: Class.forName(“oracle.jdbc.driver.OracleDriver”); - DriverManager.registerDriver();
Example: DriverManager.registerDriver( mydriver );
Database URL Formation:
- DriverManager.getConnection();
Create Connection Object:
- DriverManager.getConnection();
Interfaces:
- Statements (used for general-purpose access to database, useful when using g static SQL statements at runtime but interface cannot accept parameters)
- PreparedStatment (useful when using SQL statements multiple times and can accept interface input parameters at runtime)
- CallableStatments (use when accessing database stored procedures and is able to accept runtime input parameters)
#Type of ResultSet
- ResultSet.Type_FORWARD_ONLY (The cursor can only move forward in the result set)
- ResultSet.TYPE_SCROLL_INSENSITIVE (the cursor can move both forward and backward, and the result set is not sensitive to changes made by others to the database that occurred after result set is created)
- ResultSet.TYPE_scroll_SENSITIVE (he cursor can move both forward and backward, and the result set is sensitive to changes made by others to the database that occurred after result set is created)
Concurrency of ResultSet
*ResultSet.CONCUR_READ_ONLY (Creates a read-only result set. This is default) *ResultSet.CONCUR_UPDATABLE (Creates a updateable result set)