SlideShare a Scribd company logo
JDBC
SYNOPSIS
• What is JDBC?
• Architecture of JDBC
• Types of JDBC drivers
• Steps to connect database
What is JDBC
• JDBC – Java Database Connectivity
• JDBC is a standard java API for independent database
connection between a java program and wide range of
relational database
• It is present in the “java.sql” package
Architecture of JDBC
Types of JDBC driver
• Type 1: jdbc-odbc bridge driver
• Type 2: net protocols all java driver
• Type 3: native API partly java driver
• Type 4: native protocols all java driver
How to connect ?
• Define the connection URL
• Established the connection
• Create the statement object
• Execute a query
• Process the results
• Close the connection
Connection URL
• The connection URL is Class.forName();
• For jdbc-odbc bridge driver:
class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
• For oracle driver
class.forName(“oracle.jdbc.driver.OracleDriver”);
• For MySql driver
class.forName(“com.mysql.jdbc.Driver”);
Establishing the connection
• Connection con =
Driver.Manager.getConnection(“url”,”user_name”,”pass
word”);
• Statement stmt = con.createStatement();
Executing queries
• For select queries
Stmt.executeQuery(select * from tab_name);
• For insert queries
Stmt.executeQuery(insert into tab_name
values(1,”hello”));
Process results
ResultSet rs = stmt.executeQuery(some query);
While(rs.next())
{
System.out.println(rs.getInt(id));
System.out.println(rs.getString(name));
}
Close connection
• Close the connection using
Stmt.close();
Con.close();
Sample program

More Related Content

What's hot

Java annotations
Java annotationsJava annotations
Java annotations
FAROOK Samath
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
Vikas Jagtap
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in JavaAbhilash Nair
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
Anurag
 
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
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
Taha Malampatti
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
Funnelll
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
josemachoco
 

What's hot (20)

Java annotations
Java annotationsJava annotations
Java annotations
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Jdbc
JdbcJdbc
Jdbc
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Interface in java
Interface in javaInterface in java
Interface in java
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
 

Similar to Jdbc connectivity in java

Jsp + My Sql
Jsp + My SqlJsp + My Sql
Jsp + My Sql
Ashwin K
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
kingkolju
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
BekiTube
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
ssuser8878c1
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
NaveenKumar648465
 
Jdbc
JdbcJdbc
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
arikazukito
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
Java Database Connectivity (Advanced programming)
Java Database Connectivity (Advanced programming)Java Database Connectivity (Advanced programming)
Java Database Connectivity (Advanced programming)
Gera Paulos
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
Hemo Chella
 
Jdbc
JdbcJdbc
java.pptx
java.pptxjava.pptx
java.pptx
bfgd1
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
Pallepati Vasavi
 
Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5
Pallepati Vasavi
 

Similar to Jdbc connectivity in java (20)

Jsp + My Sql
Jsp + My SqlJsp + My Sql
Jsp + My Sql
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Java Database Connectivity (Advanced programming)
Java Database Connectivity (Advanced programming)Java Database Connectivity (Advanced programming)
Java Database Connectivity (Advanced programming)
 
JDBC
JDBCJDBC
JDBC
 
jdbc
jdbcjdbc
jdbc
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Jdbc
JdbcJdbc
Jdbc
 
java.pptx
java.pptxjava.pptx
java.pptx
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
 
Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5Mobile Application Devlopement-Database connections-UNIT-5
Mobile Application Devlopement-Database connections-UNIT-5
 

More from Muthukumaran Subramanian

Struts introduction
Struts introductionStruts introduction
Struts introduction
Muthukumaran Subramanian
 
Operators in java
Operators in javaOperators in java
Operators in java
Muthukumaran Subramanian
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
Muthukumaran Subramanian
 
Non access modifiers
Non access modifiersNon access modifiers
Non access modifiers
Muthukumaran Subramanian
 
Garbage collection in java
Garbage collection in javaGarbage collection in java
Garbage collection in java
Muthukumaran Subramanian
 
Files in java
Files in javaFiles in java
Exception handling
Exception handlingException handling
Exception handling
Muthukumaran Subramanian
 
Date class
Date classDate class
Currency class
Currency classCurrency class
Currency class
Muthukumaran Subramanian
 
Calendar class in java
Calendar class in javaCalendar class in java
Calendar class in java
Muthukumaran Subramanian
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
Muthukumaran Subramanian
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
Muthukumaran Subramanian
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
Muthukumaran Subramanian
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
Muthukumaran Subramanian
 
Java introduction
Java introductionJava introduction
Java introduction
Muthukumaran Subramanian
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 

More from Muthukumaran Subramanian (20)

Struts introduction
Struts introductionStruts introduction
Struts introduction
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Overriding methods
Overriding methodsOverriding methods
Overriding methods
 
Oops (inheritance&interface)
Oops (inheritance&interface)Oops (inheritance&interface)
Oops (inheritance&interface)
 
Non access modifiers
Non access modifiersNon access modifiers
Non access modifiers
 
Garbage collection in java
Garbage collection in javaGarbage collection in java
Garbage collection in java
 
Files in java
Files in javaFiles in java
Files in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Date class
Date classDate class
Date class
 
Currency class
Currency classCurrency class
Currency class
 
Timer class in java
Timer class in javaTimer class in java
Timer class in java
 
Calendar class in java
Calendar class in javaCalendar class in java
Calendar class in java
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Java introduction
Java introductionJava introduction
Java introduction
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 

Recently uploaded

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

Jdbc connectivity in java

  • 2. SYNOPSIS • What is JDBC? • Architecture of JDBC • Types of JDBC drivers • Steps to connect database
  • 3. What is JDBC • JDBC – Java Database Connectivity • JDBC is a standard java API for independent database connection between a java program and wide range of relational database • It is present in the “java.sql” package
  • 5. Types of JDBC driver • Type 1: jdbc-odbc bridge driver • Type 2: net protocols all java driver • Type 3: native API partly java driver • Type 4: native protocols all java driver
  • 6. How to connect ? • Define the connection URL • Established the connection • Create the statement object • Execute a query • Process the results • Close the connection
  • 7. Connection URL • The connection URL is Class.forName(); • For jdbc-odbc bridge driver: class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); • For oracle driver class.forName(“oracle.jdbc.driver.OracleDriver”); • For MySql driver class.forName(“com.mysql.jdbc.Driver”);
  • 8. Establishing the connection • Connection con = Driver.Manager.getConnection(“url”,”user_name”,”pass word”); • Statement stmt = con.createStatement();
  • 9. Executing queries • For select queries Stmt.executeQuery(select * from tab_name); • For insert queries Stmt.executeQuery(insert into tab_name values(1,”hello”));
  • 10. Process results ResultSet rs = stmt.executeQuery(some query); While(rs.next()) { System.out.println(rs.getInt(id)); System.out.println(rs.getString(name)); }
  • 11. Close connection • Close the connection using Stmt.close(); Con.close();