Slot 6,7,8,9,10 JDBC
Slot 6,7,8,9,10 JDBC
Slot 6,7,8,9,10 JDBC
References:
• Java-Tutorials/tutorial-2015/jdbc/index.html
• Java Documentation, the java.sql package
Why should you study this lecture?
Introduction to databases
Relational Database Overview
JDBC and JDBC Drivers
Steps to develop a JDBC application.
Demonstrations.
Contents
Data Manipulating
Language (DML):
SELECT…/ INSERT INTO
… / UPDATE … / DELETE
DriverManager executeQuery()
createStatement()
getConnection()
Process rs
Specific JDBC Driver
implement interfaces
(loaded dynamically
by java.lang.Class)
Application
Communicates directly with the
database using Java sockets Java Application
Improves the performance as
translation is not required
Converts JDBC queries into native
Type IV JDBC
calls used by the particular
Driver
RDBMS
The driver library is required when
SQL command Result Set
it is used and attached with the
deployed application (sqlserver
2000: mssqlserver.jar, msutil.jar, use Proprietary protocol
msbase.jar; sqlserver 2005:
sqljdbc.jar; jtds: jtds.jar …) Database
Independent platform
Download Type 4 SQL Server JDBC
Righ
t
click
Attention: Disable VIA
Stop then restart SQL Server and SQL Server Agent for settings are affected.
Righ
t
click
4-Steps to Develop a JDBC Application
Driver Class
Attention!!!
At a time, a connection can be bound with ONLY ONE result set.
An exception will be thrown if we try binding a connection with another result
set.
EX:
String sql1 =“SELECT…”;
String sql2 =“SELECT…”;
ResultSet rs1= stmt.executeQuery(sql1);
ResultSet rs2= stmt.executeQuery(sql2); EXCEPTION
You should close the rs1 before trying get the rs2 result set
Solution: Transfer data in the rs1 to ArrayList (or Vector) then close rs1 before
get new data to rs2.
Demonstrations
(Demo 1) Create database
Program GUI
Demo 3…
Introduction to databases
Relational Database Overview
JDBC and JDBC Drivers
Steps to develop a JDBC application.
Demonstrations
Thank You