Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

JDBC tutorial v1.2 (for VP STTP)

Tutorial on Java Database Connectivity for beginners
by

Asif Rampurawala

on 4 February 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of JDBC tutorial v1.2 (for VP STTP)

Java Databse Connectivity Seven Steps Of JDBC
1.Import Package
First import the java.sql package which contains all the APIs required for JDBC

2.Load Driver
Load the the Driver required for making connection using JDBC

3.Get Connection
Establish a connection with the Database using the DriverManager class

4.Create Statement
A object of Statement / PreparedStatement / CallableStatement to created before execution

5.Execute the Statement
Using the Statement object execute the required SQL statement like Insert or Select query etc.

6.Get and process the ResultSet
If a select query is executed get the ResultSet object which contains the set of all records generated by the query.

7.Close the connection
Do close the connection when the objects are no longer required.
Package java.sql Class:
~~~~~~
Class
DriverManager

Interfaces:
~~~~~~~~~~~
Connection
Statement
PreparedStatement
Callable Statement
ResultSet
ResultSetMetaData Three Tier Model Two Tier Model JDBC Architecture Types of JDBC drivers Type 2 Driver (The Native-API Driver)

The JDBC type 2 driver, also known as the Native-API driver is a database driver implementation that uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. Type 4 (The Native-Protocol Driver)

The JDBC type 4 driver, also known as the native-protocol driver is a database driver implementation that converts JDBC calls directly into the vendor-specific database protocol.The type 4 driver is written completely in Java and is hence platform independent. It is installed inside the Java Virtual Machine of the client. class Class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Class DriverManager Connection getConnection(String url)

Connection getConnection(String url, String user, String pwd)

Driver getDriver(String url)

Enumeration getDrivers()
void close()

void commit()

Statement createStatement()

DatabaseMetaData getMetaData()

CallableStatement prepareCall(String sql)

PreparedStatement prepareStatement(String sql)

void rollback()

void setAutoCommit(boolean autoCommit)
Interface Connection void close()

boolean execute(String sql)

ResultSet executeQuery(String sql)

int executeUpdate(String sql)

ResultSet getResultSet()

int getUpdateCount()

Interface Statement Interface PreparedStatement boolean execute()

ResultSet executeQuery()

int executeUpdate()

ResultSetMetaData getMetaData()

void setT(int index, T x)
T stands for any datatype in java
Eg. Byte, String, int, double etc.
Interface ResultSet boolean absolute(int row)

void close()

boolean first()

XXX getXXX(int columnIndex / String colmnName )

boolean last()

boolean next()

boolean previous()

ResultSetMetaData getMetaData()
Interface ResultSetMetaData int getColumnCount()

String getColumnName(int column)

String getColumnTypeName(int column)

String getTableName(int column)

boolean isReadOnly(int column)

boolean isWritable(int column)
Asif Rampurawala Last revised: 4th Feb, 2011 Type 3 driver (The Network-Protocol Driver)

The JDBC type 3 driver, also known as the network-protocol driver is a database driver implementation which makes use of a middle-tier between the calling program and the database. The middle-tier (application server) converts JDBC calls directly or indirectly into the vendor-specific database protocol. These drivers use a networking protocol and middleware to communicate with a server. The server then translates the protocol to DBMS function calls specific to DBMS.
Type 1 Driver (The JDBC-ODBC bridge)

The JDBC type 1 driver, also known as the JDBC-ODBC bridge is a database driver implementation that employs the ODBC driver to connect to the database. The driver converts JDBC method calls into ODBC function calls. Asst. Professor,
Vidyalankar School of Information Technology
Full transcript