Thursday, May 5, 2016

JDBC - Java Platform: Working with Databases Using JDBC. Pluralsight course, my notes

JDBC driver manager






















JDBC 4 types of drivers

JDBC Driver Type 1: JDBC ODBC bridge driver:

JDBC ODBC bridge architecture













JDBC Driver Type 2: Native-API driver (faster than Type 1):

jdbc type 3 driver native-API



JDBC Driver Type 3: Network-protocol driver (performance will be slower):




JDBC Driver Type 4: Database-protocol driver 
(direct connect to DBMS, performance will be very fast):

jdbc type 4 database protocol driver



ORACLE database install details
oracle install details























Connection to DB, database URL:
static final String dbUrl = "jdbc:oracle:thin:@localhost:1521:xe";
protocol: jdbc 
sub-protocol: oracle 
driver: thin
host name: localhost
jdbc port: 1521
oracle service name: xe

ORACLE database install details
ResultSet have 3 category of methods:
- Navigational methods
- Get methods
- Update methods

ResultSet Types:
- Type_Forward_Only (by default): moves cursor only forward
- Type_Scroll_Insensitive: forward and backward. ResultSet is not sensitive to the DB changes that occurs after result was created.
Type_Scroll_Sensitive: forward and backward. ResultSet is sensitive to the DB changes that occurs after result was created.

ResultSet Concurrency Types:
Concur_Read_Only (by default): creates read only ResultSet
Concur_Updatable:creates an updatable ResultSet

Oracle: how to create table
CREATE TABLE NewEmployees
(
EMPLOYEE_ID number(6) NOT NULL,
EMPLOYEE_NAME varchar2(25) NOT NULL,
EMAIL varchar2(25) NOT NULL,
HIRE_DATE date NOT NULL,
SALARY number(8,2)
);

Result:
SQL> desc NewEmployees
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPLOYEE_ID                               NOT NULL NUMBER(6)
 EMPLOYEE_NAME                             NOT NULL VARCHAR2(25)
 EMAIL                                     NOT NULL VARCHAR2(25)
 HIRE_DATE                                 NOT NULL DATE
 SALARY                                             NUMBER(8,2)

SQL>

Oracle: how to insert values
INSERT INTO NewEmployees VALUES (100, 'Andre', 'andre@gmail.com', '2016-05-5',1000);

CallableStatement parameters:
- Input
- Output
- Input Output
- Return ResultSet
A CallableStatement are used to make a call to the Stored Procedures.



Store Procedure
Is a group of SQL Statements that perform a particular task.





asdf
asd
as








asdf

No comments: