SlideShare a Scribd company logo
JAVA
JDBC
Prepared by
Miss. Arati A. Gadgil
JDBC
Java JDBC is a java API to connect and execute query with the
database. JDBC API uses jdbc drivers to connect with the database.
API
API (Application programming interface) is a document that
contains description of all the features of a product or software. It
represents classes and interfaces that software programs can follow
to communicate with each other. An API can be created for
applications, libraries, operating systems, etc
JDBCDriver
JDBC Driver is a software component that enables java application to
interact with the database. There are 4 types of JDBC drivers
1.JDBC-ODBC bridge driver
2.Native-API driver (partially java driver)
3.Network Protocol driver (fully java driver)
4.Thin driver (fully java driver)
JDBC-ODBC bridge driver
The JDBC-ODBC bridge driver uses ODBC driver to connect to the
database. The JDBC-ODBC bridge driver converts JDBC method calls
into the ODBC function calls.
connect to the database
Steps
1. Register the driver class
2. Creating connection
3. Creating statement
4. Executing queries
5. Closing connection
1) Register the driver class
public static void forName(String className)throws
ClassNotFoundException
Example
Class.forName("oracle.jdbc.driver.OracleDriver");
2)Create the connection object
1) public static Connection getConnection(String url)throws
SQLException
2) public static Connection getConnection(String url,String name,String
password) throws SQLException
Example
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","password");
3) Create the Statement object
The createStatement() method of Connection interface is used to create
statement.
The object of statement is responsible to execute queries with the
database.
public Statement createStatement()throws SQLException
Example
Statement stmt=con.createStatement();
4) Execute the query
The executeQuery() method of Statement interface is used to execute
queries to the database.
This method returns the object of ResultSet that can be used to get all
the records of a table.
public ResultSet executeQuery(String sql)throws SQLException
Example
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
5) Close the connection object
By closing connection object statement and ResultSet will be closed
automatically.
The close() method of Connection interface is used to close the
connection.
public void close()throws SQLException
Example
con.close();
DatabaseMetaData Interface
DatabaseMetaData interface provides methods to get meta data of a
database such as database product name, database product version,
driver name, name of total number of tables, name of total number of
views etc.
Methods
public String getDriverName()throws SQLException
it returns the name of the JDBC driver.
public String getDriverVersion()throws SQLException
it returns the version number of the JDBC driver.
public String getUserName()throws SQLException
it returns the username of the database.
public String getDatabaseProductName()throws SQLException
it returns the product name of the database.
public String getDatabaseProductVersion()throws SQLException
it returns the product version of the database.
public ResultSet getTables(String catalog, String schemaPattern,
String tableNamePattern, String[] types)throws SQLException
it returns the description of the tables of the specified catalog. The
table type can be TABLE, VIEW, ALIAS, SYSTEM TABLE,
SYNONYM etc.
Transaction
Transaction represents a single unit of work
Properties
Atomicity means either all successful or none.
Consistency ensures bringing the database from one consistent state to
another consistent state.
Isolation ensures that transaction is isolated from other transaction.
Durability means once a transaction has been committed, it will remain
so, even in the event of errors, power loss etc.
 Connectioninterface
In JDBC, Connection interface provides methods to manage
transaction.
Methods
void setAutoCommit(boolean status)
It is true bydefault means each transaction is committed by
default.
void commit()
commits the transaction.
void rollback()
cancels the transaction.
What is JDBC?
JDBC stands for Java Database Connectivity, which is a standard Java
API for database-independent connectivity between the Java prog
ramming language and a wide range of databases.
Common JDBC Components
DriverManager: This class manages a list of database drivers.
Driver: This interface handles the communications with the database
server.
Connec tion: This interface with all methods for contacting a database.
Statement: You use objects created from this interface to submit the
SQL statements to the database.
ResultSet: These objects hold data retrieved from a database after you
execute an SQL query using Statement objects. It acts as an iterator to
allow you to move throug h its data.
SQLException: T his class handles any errors that occur in a database
application.
JDBC-SQLSYNTAX
Structured Query Language (SQL) is a standardized language that allows
you to perform operations on a database, such as creating entries, reading
content, updating content, and deleting entries.
Create Database:
The CREAT E DATABASE statement is used for creating a new
database. The syntax is:
SQL> CREATE DATABASE DATABASE_NAME;
Example
The following SQL statement creates a Database named EMP:
SQL> CREATE DATABASE EMP;
Drop Database:
The DROP DATABASE statement is used for deleting an existing
database. The syntax is:
SQL> DROP DATABASE DATABASE_NAME;
Create Table:
The CREAT E TABLE statement is used for creating a new table. The
syntax is:
SQL> CREATE TABLE table_name
(
column_name column_data_type,
...
);
Example:
The following SQL statement creates a table named Employees with four
columns:
SQL> CREATE TABLE Employees
( id INT NOT NULL,
age INT NOT NULL,
first VARCHAR(255),
last VARCHAR(255),
PRIMARY KEY ( id )
);
INSERT Data:
The syntax for INSERT looks similar to the following , where column1,
column2, and so on represent the new data to appear in the respective
columns:
SQL> INSERT INTO table_name VALUES (column1, column2, ...);
Example:
The following SQL INSERT statement inserts a new row in the
Employees database created earlier:
SQL> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
SELECT Data:
The SELECT statement is used to retrieve data from a database. The
syntax for SELECT is:
SQL> SELECT column_name, column_name, ...
FROM table_name
WHERE conditions;
The WHERE clause can use the comparison operators such as =, !=, <,
>, <=,and >=, as well as the BETWEEN
and LIKE operators.
Example
The following SQL statement selects the ag e, first and last columns
from the Employees table where id column is
100:
SQL> SELECT first, last, age
FROM Employees
WHERE id = 100;
The following SQL statement selects the age, first and last columns from
the Employees table where first column contains Zara
SQL> SELECT first, last, age
FROM Employees
WHERE first LIKE '%Zara%';
The following SQL statement selects the age, first and last columns from
the Employees table where first column contains “a” at end
SQL> SELECT first, last, age
FROM Employees
WHERE first LIKE '%a';
The following SQL statement selects the age, first and last columns from
the Employees table where first column contains a at start
SQL> SELECT first, last, age
FROM Employees
WHERE first LIKE 'a%';
UPDATE Data:
The UPDAT E statement is used to update data. The syntax for
UPDATE is:
SQL> UPDATE table_name
SET column_name = value, column_name = value, ...
WHERE conditions;
The WHERE clause can use the comparison operators such as =, !=, <,
>, <=,and >=, as well as the BETWEEN
and LIKE operators.
Example:
T he following SQL UPDAT E statement changes the age column of the
employee whose id is 100:
SQL> UPDATE Employees SET age=20 WHERE id=100;
DELETE Data:
The DELETE statement is used to delete data from tables. The syntax for
DELETE is:
SQL> DELETE FROM table_name WHERE conditions;
The WHERE clause can use the comparison operators such as =, !=, <,
>, <=,and >=, as well as the BETWEEN
and LIKE operators.
Example:
T he following SQL DELET E statement delete the record of the
employee whose id is 100:
SQL> DELETE FROM Employees WHERE id=100;
ImportJDBCPackages
import java.sql.* ; // for standard JDBC programs
import java.math.* ; // for BigDecimal and BigInteger support
Register JDBC Driver
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException ex)
{
System.out.println("Error: unable to load driver class!");
System.exit(1);
}
Create Connection Object:
Using a database URL with a username and password:
String URL = "jdbc:oracle:thin:@amrood:1521:EMP";
String USER = "username";
String PASS = "password"
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Closing JDBC connections:
conn.close();
Statement
Use for general-purpose access to your database. Useful when you are
using static SQL statements at runtime. T he Statement interface cannot
accept parameters.
PreparedStatement :
Use when you plan to use the SQL statements many times. The
PreparedStatement interface accepts input parameters at runtime.
CallableStatement :
Use when you want to access database stored procedures. The
CallableStatement interface can also accept runtime input parameters.
Creating Statement Object
Before you can use a Statement object to execute a SQL statement, you
need to create one using the Connection
object's createStatement( ) method, as in the following example:
Statement stmt = null;
try
{
stmt = conn.createStatement( );
. . .
} catch (SQLException e)
{
. . .
}
finally {
. . .
}
Once you've created a Statement object, you can then use it to execute a
SQL statement with one of its three execute methods.
boolean execute(String SQL) : Returns a boolean value of true if a
ResultSet object can be retrieved; otherwise, it returns false. Use this
method to execute SQL DDL statements or when you need to use truly
dynamic SQL.
int executeUpdate(String SQL) : Returns the numbers of rows affected
by the execution of the SQL statement. Use this method to execute SQL
statements for which you expect to get a number of rows affected - for
example, an INSERT , UPDAT E, or DELET E statement.
ResultSet executeQuery(String SQL) : Returns a ResultSet object. Use
this method when you expect to get a result set, as you would with a
SELECT statement.
31
Rowsets
Rowsets are the central objects that enable OLE DB components to
expose and manipulate data in tabular form. A rowset object is a set of
rows in which each row has columns of data.
Query processors present query results in the form of rowsets.
32
ResultSet
The SQL statements that read data from a database query, return the data
in a result set. The SELECT statement is the standard way to select rows
from a database and view them in a result set.
The java.sql.ResultSet interface represents the result set of a database
query.
A ResultSet object maintains a cursor that points to the current row in
the result set. The term "result set" refers to the row and column data
contained in a ResultSet object.
The ResultSet interface contains many methods for getting the data of
the current row.
33
public int getInt(String columnName) throws SQLException
Returns the int in the current row in the column named
columnName
public int getInt(int columnIndex) throws SQLException
Returns the int in the current row in the specified column index.
The column index starts at 1, meaning the first column of a row is
1, the second column of a row is 2, and so on.
Similarly, there are get methods in the ResultSet interface for each of the
eight Java primitive types, as well as common types such as
java.lang.String, java.lang.Object, and java.net.URL
Thank You
34

More Related Content

What's hot

JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
Information Technology
 
Jdbc
JdbcJdbc
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
Fad Zulkifli
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
Adil Mehmoood
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
Database connect
Database connectDatabase connect
Database connect
Yoga Raja
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
Nuha Noor
 
Jdbc
JdbcJdbc
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
Sasidhar Kothuru
 
Jdbc
JdbcJdbc
Best Of Jdk 7
Best Of Jdk 7Best Of Jdk 7
Best Of Jdk 7
Kaniska Mandal
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
hameedkhan2017
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
leminhvuong
 

What's hot (20)

JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Jdbc
JdbcJdbc
Jdbc
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Database connect
Database connectDatabase connect
Database connect
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Jdbc
JdbcJdbc
Jdbc
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
Jdbc
JdbcJdbc
Jdbc
 
Best Of Jdk 7
Best Of Jdk 7Best Of Jdk 7
Best Of Jdk 7
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 

Viewers also liked

Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBC
Hemant Sharma
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
Mindfire Solutions
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
chhaichivon
 
Prativa biswas
Prativa biswasPrativa biswas
Prativa biswas
Prativa Biswas
 
Andrew_Parker_-_resume3a
Andrew_Parker_-_resume3aAndrew_Parker_-_resume3a
Andrew_Parker_-_resume3a
Andrew Parker
 
CATEAR SERVICES
CATEAR SERVICESCATEAR SERVICES
CATEAR SERVICES
CATEAR SERVICES
 
ABC of Public Relations. Presentation Outline
ABC of Public Relations. Presentation OutlineABC of Public Relations. Presentation Outline
ABC of Public Relations. Presentation Outline
Bogdan-Sorin Popescu
 
Hizib nashor
Hizib nashorHizib nashor
Hizib nashor
SARNITA TOHA
 
Dissertation Completed
Dissertation CompletedDissertation Completed
Dissertation Completed
Joel Huskisson
 
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineenaSivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
Natural Resources Institute Finland (Luke) / Luonnonvarakeskus (Luke)
 
Teoriascreatividad
TeoriascreatividadTeoriascreatividad
Teoriascreatividad
Claudia Reyes
 
Uudet proteiinilahteet
Uudet proteiinilahteetUudet proteiinilahteet
Estrutura condicional com Ruby[AULA-2]
Estrutura condicional com Ruby[AULA-2]Estrutura condicional com Ruby[AULA-2]
Estrutura condicional com Ruby[AULA-2]
Ricardo Silva
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
Vikas Jagtap
 
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
VTT Technical Research Centre of Finland Ltd
 
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017 Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
VTT Technical Research Centre of Finland Ltd
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Gestion e innovacion educativa ccesa007
Gestion e  innovacion educativa  ccesa007Gestion e  innovacion educativa  ccesa007
Gestion e innovacion educativa ccesa007
Demetrio Ccesa Rayme
 

Viewers also liked (18)

Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBC
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Prativa biswas
Prativa biswasPrativa biswas
Prativa biswas
 
Andrew_Parker_-_resume3a
Andrew_Parker_-_resume3aAndrew_Parker_-_resume3a
Andrew_Parker_-_resume3a
 
CATEAR SERVICES
CATEAR SERVICESCATEAR SERVICES
CATEAR SERVICES
 
ABC of Public Relations. Presentation Outline
ABC of Public Relations. Presentation OutlineABC of Public Relations. Presentation Outline
ABC of Public Relations. Presentation Outline
 
Hizib nashor
Hizib nashorHizib nashor
Hizib nashor
 
Dissertation Completed
Dissertation CompletedDissertation Completed
Dissertation Completed
 
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineenaSivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
Sivuhyöty 13.10.2016 kasvisivutuote maanparannusaineena
 
Teoriascreatividad
TeoriascreatividadTeoriascreatividad
Teoriascreatividad
 
Uudet proteiinilahteet
Uudet proteiinilahteetUudet proteiinilahteet
Uudet proteiinilahteet
 
Estrutura condicional com Ruby[AULA-2]
Estrutura condicional com Ruby[AULA-2]Estrutura condicional com Ruby[AULA-2]
Estrutura condicional com Ruby[AULA-2]
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
Perttu Antila, LUKE: Riittääkö metsähaketta kaikille?
 
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017 Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
Foresight Friday: Kohti jaettua ymmärrystä työn tulevaisuudesta 3.3.2017
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Gestion e innovacion educativa ccesa007
Gestion e  innovacion educativa  ccesa007Gestion e  innovacion educativa  ccesa007
Gestion e innovacion educativa ccesa007
 

Similar to Java jdbc

jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
Fulvio Corno
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
Waheedullah Suliman Khail
 
jdbc
jdbcjdbc
Chapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptxChapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptx
BlenKassahun1
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
ChagantiSahith
 
JDBC
JDBCJDBC
Mule jdbc
Mule   jdbcMule   jdbc
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
Dharma Kshetri
 
03-JDBC.pptx
03-JDBC.pptx03-JDBC.pptx
03-JDBC.pptx
HachaluHaile
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
phanleson
 
Advance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-databaseAdvance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-database
Payal Dungarwal
 
Jdbc
JdbcJdbc
Java beans
Java beansJava beans
Java beans
Sher Singh Bardhan
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.ppt
TabassumMaktum
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 

Similar to Java jdbc (20)

jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Lecture 1. java database connectivity
Lecture 1. java database connectivityLecture 1. java database connectivity
Lecture 1. java database connectivity
 
jdbc
jdbcjdbc
jdbc
 
Chapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptxChapter Seven- JDBC.pptx
Chapter Seven- JDBC.pptx
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
JDBC
JDBCJDBC
JDBC
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
 
03-JDBC.pptx
03-JDBC.pptx03-JDBC.pptx
03-JDBC.pptx
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
Advance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-databaseAdvance Java Programming (CM5I)5.Interacting with-database
Advance Java Programming (CM5I)5.Interacting with-database
 
Jdbc
JdbcJdbc
Jdbc
 
Java beans
Java beansJava beans
Java beans
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
 
Lecture17
Lecture17Lecture17
Lecture17
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.ppt
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 

More from Arati Gadgil

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
 
Java swing
Java swingJava swing
Java swing
 
Java applet
Java appletJava applet
Java applet
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Java awt
Java awtJava awt
Java awt
 
Java stream
Java streamJava stream
Java stream
 
Java thread
Java threadJava thread
Java thread
 
Java networking
Java networkingJava networking
Java networking
 
Java package
Java packageJava package
Java package
 
Java interface
Java interfaceJava interface
Java interface
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Java exception
Java exception Java exception
Java exception
 
Java collection
Java collectionJava collection
Java collection
 
Java class
Java classJava class
Java class
 
Java basic
Java basicJava basic
Java basic
 

Recently uploaded

Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
IsmaelVazquez38
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
David Douglas School District
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 

Recently uploaded (20)

Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 

Java jdbc

  • 2. JDBC Java JDBC is a java API to connect and execute query with the database. JDBC API uses jdbc drivers to connect with the database.
  • 3. API API (Application programming interface) is a document that contains description of all the features of a product or software. It represents classes and interfaces that software programs can follow to communicate with each other. An API can be created for applications, libraries, operating systems, etc
  • 4. JDBCDriver JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers 1.JDBC-ODBC bridge driver 2.Native-API driver (partially java driver) 3.Network Protocol driver (fully java driver) 4.Thin driver (fully java driver)
  • 5. JDBC-ODBC bridge driver The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls.
  • 6. connect to the database Steps 1. Register the driver class 2. Creating connection 3. Creating statement 4. Executing queries 5. Closing connection
  • 7. 1) Register the driver class public static void forName(String className)throws ClassNotFoundException Example Class.forName("oracle.jdbc.driver.OracleDriver");
  • 8. 2)Create the connection object 1) public static Connection getConnection(String url)throws SQLException 2) public static Connection getConnection(String url,String name,String password) throws SQLException Example Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","password");
  • 9. 3) Create the Statement object The createStatement() method of Connection interface is used to create statement. The object of statement is responsible to execute queries with the database. public Statement createStatement()throws SQLException Example Statement stmt=con.createStatement();
  • 10. 4) Execute the query The executeQuery() method of Statement interface is used to execute queries to the database. This method returns the object of ResultSet that can be used to get all the records of a table. public ResultSet executeQuery(String sql)throws SQLException Example ResultSet rs=stmt.executeQuery("select * from emp"); while(rs.next()) { System.out.println(rs.getInt(1)+" "+rs.getString(2)); }
  • 11. 5) Close the connection object By closing connection object statement and ResultSet will be closed automatically. The close() method of Connection interface is used to close the connection. public void close()throws SQLException Example con.close();
  • 12. DatabaseMetaData Interface DatabaseMetaData interface provides methods to get meta data of a database such as database product name, database product version, driver name, name of total number of tables, name of total number of views etc.
  • 13. Methods public String getDriverName()throws SQLException it returns the name of the JDBC driver. public String getDriverVersion()throws SQLException it returns the version number of the JDBC driver. public String getUserName()throws SQLException it returns the username of the database. public String getDatabaseProductName()throws SQLException it returns the product name of the database. public String getDatabaseProductVersion()throws SQLException it returns the product version of the database. public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)throws SQLException it returns the description of the tables of the specified catalog. The table type can be TABLE, VIEW, ALIAS, SYSTEM TABLE, SYNONYM etc.
  • 14. Transaction Transaction represents a single unit of work Properties Atomicity means either all successful or none. Consistency ensures bringing the database from one consistent state to another consistent state. Isolation ensures that transaction is isolated from other transaction. Durability means once a transaction has been committed, it will remain so, even in the event of errors, power loss etc.
  • 15.
  • 16.  Connectioninterface In JDBC, Connection interface provides methods to manage transaction. Methods void setAutoCommit(boolean status) It is true bydefault means each transaction is committed by default. void commit() commits the transaction. void rollback() cancels the transaction.
  • 17. What is JDBC? JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java prog ramming language and a wide range of databases. Common JDBC Components DriverManager: This class manages a list of database drivers. Driver: This interface handles the communications with the database server. Connec tion: This interface with all methods for contacting a database. Statement: You use objects created from this interface to submit the SQL statements to the database. ResultSet: These objects hold data retrieved from a database after you execute an SQL query using Statement objects. It acts as an iterator to allow you to move throug h its data. SQLException: T his class handles any errors that occur in a database application.
  • 18.
  • 19. JDBC-SQLSYNTAX Structured Query Language (SQL) is a standardized language that allows you to perform operations on a database, such as creating entries, reading content, updating content, and deleting entries. Create Database: The CREAT E DATABASE statement is used for creating a new database. The syntax is: SQL> CREATE DATABASE DATABASE_NAME; Example The following SQL statement creates a Database named EMP: SQL> CREATE DATABASE EMP; Drop Database: The DROP DATABASE statement is used for deleting an existing database. The syntax is: SQL> DROP DATABASE DATABASE_NAME;
  • 20. Create Table: The CREAT E TABLE statement is used for creating a new table. The syntax is: SQL> CREATE TABLE table_name ( column_name column_data_type, ... ); Example: The following SQL statement creates a table named Employees with four columns: SQL> CREATE TABLE Employees ( id INT NOT NULL, age INT NOT NULL, first VARCHAR(255), last VARCHAR(255), PRIMARY KEY ( id ) );
  • 21. INSERT Data: The syntax for INSERT looks similar to the following , where column1, column2, and so on represent the new data to appear in the respective columns: SQL> INSERT INTO table_name VALUES (column1, column2, ...); Example: The following SQL INSERT statement inserts a new row in the Employees database created earlier: SQL> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
  • 22. SELECT Data: The SELECT statement is used to retrieve data from a database. The syntax for SELECT is: SQL> SELECT column_name, column_name, ... FROM table_name WHERE conditions; The WHERE clause can use the comparison operators such as =, !=, <, >, <=,and >=, as well as the BETWEEN and LIKE operators. Example The following SQL statement selects the ag e, first and last columns from the Employees table where id column is 100: SQL> SELECT first, last, age FROM Employees WHERE id = 100;
  • 23. The following SQL statement selects the age, first and last columns from the Employees table where first column contains Zara SQL> SELECT first, last, age FROM Employees WHERE first LIKE '%Zara%'; The following SQL statement selects the age, first and last columns from the Employees table where first column contains “a” at end SQL> SELECT first, last, age FROM Employees WHERE first LIKE '%a'; The following SQL statement selects the age, first and last columns from the Employees table where first column contains a at start SQL> SELECT first, last, age FROM Employees WHERE first LIKE 'a%';
  • 24. UPDATE Data: The UPDAT E statement is used to update data. The syntax for UPDATE is: SQL> UPDATE table_name SET column_name = value, column_name = value, ... WHERE conditions; The WHERE clause can use the comparison operators such as =, !=, <, >, <=,and >=, as well as the BETWEEN and LIKE operators. Example: T he following SQL UPDAT E statement changes the age column of the employee whose id is 100: SQL> UPDATE Employees SET age=20 WHERE id=100;
  • 25. DELETE Data: The DELETE statement is used to delete data from tables. The syntax for DELETE is: SQL> DELETE FROM table_name WHERE conditions; The WHERE clause can use the comparison operators such as =, !=, <, >, <=,and >=, as well as the BETWEEN and LIKE operators. Example: T he following SQL DELET E statement delete the record of the employee whose id is 100: SQL> DELETE FROM Employees WHERE id=100;
  • 26. ImportJDBCPackages import java.sql.* ; // for standard JDBC programs import java.math.* ; // for BigDecimal and BigInteger support Register JDBC Driver try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException ex) { System.out.println("Error: unable to load driver class!"); System.exit(1); }
  • 27. Create Connection Object: Using a database URL with a username and password: String URL = "jdbc:oracle:thin:@amrood:1521:EMP"; String USER = "username"; String PASS = "password" Connection conn = DriverManager.getConnection(URL, USER, PASS); Closing JDBC connections: conn.close();
  • 28. Statement Use for general-purpose access to your database. Useful when you are using static SQL statements at runtime. T he Statement interface cannot accept parameters. PreparedStatement : Use when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime. CallableStatement : Use when you want to access database stored procedures. The CallableStatement interface can also accept runtime input parameters.
  • 29. Creating Statement Object Before you can use a Statement object to execute a SQL statement, you need to create one using the Connection object's createStatement( ) method, as in the following example: Statement stmt = null; try { stmt = conn.createStatement( ); . . . } catch (SQLException e) { . . . } finally { . . . }
  • 30. Once you've created a Statement object, you can then use it to execute a SQL statement with one of its three execute methods. boolean execute(String SQL) : Returns a boolean value of true if a ResultSet object can be retrieved; otherwise, it returns false. Use this method to execute SQL DDL statements or when you need to use truly dynamic SQL. int executeUpdate(String SQL) : Returns the numbers of rows affected by the execution of the SQL statement. Use this method to execute SQL statements for which you expect to get a number of rows affected - for example, an INSERT , UPDAT E, or DELET E statement. ResultSet executeQuery(String SQL) : Returns a ResultSet object. Use this method when you expect to get a result set, as you would with a SELECT statement.
  • 31. 31 Rowsets Rowsets are the central objects that enable OLE DB components to expose and manipulate data in tabular form. A rowset object is a set of rows in which each row has columns of data. Query processors present query results in the form of rowsets.
  • 32. 32 ResultSet The SQL statements that read data from a database query, return the data in a result set. The SELECT statement is the standard way to select rows from a database and view them in a result set. The java.sql.ResultSet interface represents the result set of a database query. A ResultSet object maintains a cursor that points to the current row in the result set. The term "result set" refers to the row and column data contained in a ResultSet object. The ResultSet interface contains many methods for getting the data of the current row.
  • 33. 33 public int getInt(String columnName) throws SQLException Returns the int in the current row in the column named columnName public int getInt(int columnIndex) throws SQLException Returns the int in the current row in the specified column index. The column index starts at 1, meaning the first column of a row is 1, the second column of a row is 2, and so on. Similarly, there are get methods in the ResultSet interface for each of the eight Java primitive types, as well as common types such as java.lang.String, java.lang.Object, and java.net.URL