SlideShare a Scribd company logo
1 of 21
by Tanmoy Barman
cont:- barmantanmoy.47@gmail.com
Discussions
 What?
 Architecture of JDBC.
 Types of JDBC driver available.
 Steps to connect to DB.
 Types of Statement.
 JDBC Data Source.
What is JDBC ?
 JDBC acronym of java Database
connectivity; though Sun Microsystems
claims that it is not the full form.
 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; native API partly java driver.
 Type 3; net protocols all java driver.
 Type 4; native protocols all java driver.
Steps to connect?
 Define the connection URL.
 Established the connection.
 Create the Statement object.
 Execute a query.
 Process the results.
 Close the connection.
Steps to connect?
 Define the connection url :
Class.forName();
 For jdbc-odbc bridge driver:-
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
 For oracle driver:-
Class.forName(“oracle.jdbc.driver.OracleDriver”);
 For My sql driver:-
Class.forName(“com.mysql.jdbc.Driver”);
Steps to connect?
 Established the connection:
Connection con
=DriverManager.getConnection(“url”,”user_name”,”pass”);
Steps to connect?
 Create the Statement object:
Statement stmt=con.createStatement();
Steps to connect?
 Execute the query:
 For the SELECT query:-
 String sql=“SELECT * FROM EMP”;
 stmt.executeQuery(sql);
 For the INSERT/UPDATE query:-
 String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;
 stmt.executeUpdate(sql);
Steps to connect?
 Process the result:-
ResultSet rs=stmt.execute Query(sql);
while(rs.next()){
System.out.println(rs.getInt(id));
System.out.print(rs.getString(name));
}
Steps to connect?
 Close the connection
release all the resources that the connection
is holding.
stmt.close();
con.close();
Steps to connect?
 Summarizing the steps for connecting java DB and inserting values in
DB, deployed on Net Beans IDE :-
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbacus","teddy","teddy");
Statement stmt=con.createStatement();
String sql=“INSERT INTO TEDDY(47,’jani’)”;
stmt.executeUpdate(sql);
stmt.close();
con.close();
Types of Statement available
 There are three types of Statement
available in Statement class:-
 Statement
 PreparedStatement
 CallableStatement
Types of Statement available
 Statement
This represent a simple sql/mysql
statement.
Statement stmt=con.createStatement();
Types of Statement available
 PreparedStatement
this represent precompiled sql/my sql
statement which allows improved
performance. It allows to execute the query
multiple times and we can set the values
according to our need.
PreparedStatement psmt=con.prepareStatement();
Types of Statement available
 CallableStatement
This allows the access of stored
procedures; that are stored on the database.
CallableStatement csmt=con.prepareCall();
JDBC Data Source
 The JDBC data source interface is an
alternative to DriverManager class and
conventional JBDC url. All the database
information is present in the Naming
service and retrieved using the JNDI API.
The Data Source object contains the
connection information which will make the
actual connection and execute the JDBC
commands.
JDBC Data Source:
 Each Data Source is assigned a logical name
by conventional beginning with jdbc/ .
 Advantages:-
○ Makes the code portable and reuse.
○ The application does not have to remember the
hardcore driver information.
○ Connection pooling and distributed transaction
advantages is facilitate.
JDBC Data Source:
 Syntax:-
Context ctx=new InitialContext();
DataSource
ds=(DataSource)ctx.lookup(“jdbc/teddyDB”);
Connection
con=ds.getConnection(“user_name”,”pass”);
Thank You

More Related Content

What's hot (20)

Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
JVM
JVMJVM
JVM
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
OOP java
OOP javaOOP java
OOP java
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Distributed database management system
Distributed database management  systemDistributed database management  system
Distributed database management system
 

Viewers also liked

Viewers also liked (20)

JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc
JdbcJdbc
Jdbc
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Jdbc
JdbcJdbc
Jdbc
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 

Similar to JDBC: java DataBase connectivity (20)

Jdbc
JdbcJdbc
Jdbc
 
Jdbc
Jdbc   Jdbc
Jdbc
 
JDBC
JDBCJDBC
JDBC
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc new
Jdbc newJdbc new
Jdbc new
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Jdbc
JdbcJdbc
Jdbc
 
java arlow jdbc tutorial(java programming tutorials)
java arlow jdbc tutorial(java programming tutorials)java arlow jdbc tutorial(java programming tutorials)
java arlow jdbc tutorial(java programming tutorials)
 
JDBC
JDBCJDBC
JDBC
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
Jdbc
JdbcJdbc
Jdbc
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
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)
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 

More from Tanmoy Barman

java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technologyTanmoy Barman
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architectureTanmoy Barman
 
introduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksintroduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksTanmoy Barman
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGTanmoy Barman
 

More from Tanmoy Barman (7)

Java rmi
Java rmiJava rmi
Java rmi
 
Jini
JiniJini
Jini
 
Java server pages
Java server pagesJava server pages
Java server pages
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
introduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksintroduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networks
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTING
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 

JDBC: java DataBase connectivity

  • 1. by Tanmoy Barman cont:- barmantanmoy.47@gmail.com
  • 2. Discussions  What?  Architecture of JDBC.  Types of JDBC driver available.  Steps to connect to DB.  Types of Statement.  JDBC Data Source.
  • 3. What is JDBC ?  JDBC acronym of java Database connectivity; though Sun Microsystems claims that it is not the full form.  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; native API partly java driver.  Type 3; net protocols all java driver.  Type 4; native protocols all java driver.
  • 6. Steps to connect?  Define the connection URL.  Established the connection.  Create the Statement object.  Execute a query.  Process the results.  Close the connection.
  • 7. Steps to connect?  Define the connection url : Class.forName();  For jdbc-odbc bridge driver:- Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);  For oracle driver:- Class.forName(“oracle.jdbc.driver.OracleDriver”);  For My sql driver:- Class.forName(“com.mysql.jdbc.Driver”);
  • 8. Steps to connect?  Established the connection: Connection con =DriverManager.getConnection(“url”,”user_name”,”pass”);
  • 9. Steps to connect?  Create the Statement object: Statement stmt=con.createStatement();
  • 10. Steps to connect?  Execute the query:  For the SELECT query:-  String sql=“SELECT * FROM EMP”;  stmt.executeQuery(sql);  For the INSERT/UPDATE query:-  String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;  stmt.executeUpdate(sql);
  • 11. Steps to connect?  Process the result:- ResultSet rs=stmt.execute Query(sql); while(rs.next()){ System.out.println(rs.getInt(id)); System.out.print(rs.getString(name)); }
  • 12. Steps to connect?  Close the connection release all the resources that the connection is holding. stmt.close(); con.close();
  • 13. Steps to connect?  Summarizing the steps for connecting java DB and inserting values in DB, deployed on Net Beans IDE :- Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbacus","teddy","teddy"); Statement stmt=con.createStatement(); String sql=“INSERT INTO TEDDY(47,’jani’)”; stmt.executeUpdate(sql); stmt.close(); con.close();
  • 14. Types of Statement available  There are three types of Statement available in Statement class:-  Statement  PreparedStatement  CallableStatement
  • 15. Types of Statement available  Statement This represent a simple sql/mysql statement. Statement stmt=con.createStatement();
  • 16. Types of Statement available  PreparedStatement this represent precompiled sql/my sql statement which allows improved performance. It allows to execute the query multiple times and we can set the values according to our need. PreparedStatement psmt=con.prepareStatement();
  • 17. Types of Statement available  CallableStatement This allows the access of stored procedures; that are stored on the database. CallableStatement csmt=con.prepareCall();
  • 18. JDBC Data Source  The JDBC data source interface is an alternative to DriverManager class and conventional JBDC url. All the database information is present in the Naming service and retrieved using the JNDI API. The Data Source object contains the connection information which will make the actual connection and execute the JDBC commands.
  • 19. JDBC Data Source:  Each Data Source is assigned a logical name by conventional beginning with jdbc/ .  Advantages:- ○ Makes the code portable and reuse. ○ The application does not have to remember the hardcore driver information. ○ Connection pooling and distributed transaction advantages is facilitate.
  • 20. JDBC Data Source:  Syntax:- Context ctx=new InitialContext(); DataSource ds=(DataSource)ctx.lookup(“jdbc/teddyDB”); Connection con=ds.getConnection(“user_name”,”pass”);