SlideShare a Scribd company logo
1 of 26
Discussions
⦿What is JDBC?
⦿What is ODBC?
⦿JDBC vs ODBC?
⦿ Architecture of JDBC.
⦿ Types of JDBC driver available.
⦿ Steps to connect to DB.
⦿ Types of Statement.
What is JDBC ?
⦿ JDBC acronym of Java Database
connectivity; though Sun Microsystems
⦿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
 JDBC is an interface between Java and Database
 JDBC receives queries from Java Application program and
communicate with Database
 All the communications are in the form of SQL commands
 JDBC is reponsible for
 Open a Connection
 Communicate with database
 Execute SQL statements
 Retrive query results
What is JDBC ?
Open DataBase Connectivity (ODBC)
 Standard designed by Microsoft to interact with
databases
 ODBC is packed with many features and extending
support for all type of databases
 ODBC provides multiple mechanism for performing
single task and number of data handling capabilities
JDBC vs ODBC
 JDBC and ODBC are X/OPEN call level interface
for SQL
 JDBC is not a derivative of ODBC
 JDBC is compact and simple
 JDBC is meant for simple access to the database and
difficult task at least make possible
Architecture of JDBC
JDBC Drivers
 JDBC driver is responsible for making connection with different
databases
 It is also translating the queries received from Application and
submit into database
 A reverse translation is also required to perform by the Driver
 JDBC Driver speaks JAVA to Application and native language
to database
 JDBC Drivers are exists for almost all databases
 Appropriate driver will load for requied database
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.
JDBC – ODBC Bridge
 It is a JDBC driver designed to let Java application
communicate with database via an underlying ODBC driver
 It is called Type I JDBC connector
 It can be used with multiple databases and is vendor
independent
 This type JDBC driver speaks only to ODBC driver, hence
works for Databases supported by ODBC
 One more added layer is used and hence more complex and
slower than JDBC drivers
Native-API-Partly-Java Driver
 It make use of local native libraries to communicate
with database
 Vendor specific Call Level Interface(CLI) installed
locally are used by this type driver
 CLI libraries are actually communicate with
database
 Application level requests are translated into
equallent native method call of CLI
 Faster than Type I driver
JDBC-Net-All-Java Driver
 Type III Driver, uses the CLI libraries locates in a remote server
 Type III driver has two major components
 An All-Java portion that can download to the client
 Server portion containing both Java and Native methods
 All communication between Application and Database is 100%
Java to Java
 This type of driver is also depending on CLI calls, which is
installed on Server
 Type III can be used in Internet, since no direct access to CLI
libraries
 Type III Network protocol is not standardized
Native-Protocol-All-Java Driver
 100% java specific drivers
 No intermediate translation is required
 But all vendor specific driver cannot released by
Java
 Java Applets are now free from Acces restrictions
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
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbac
us","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();
Thank You

More Related Content

Similar to jdbc-130913021409-phpapp01000988www.pptx

JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
JDBC Architecture and Drivers
JDBC Architecture and DriversJDBC Architecture and Drivers
JDBC Architecture and DriversSimoniShah6
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbmsKhyalNayak
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
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.pptkingkolju
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 
Chapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxChapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxBachaSirata
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)Fad Zulkifli
 
JDBC : Java Database Connectivity
JDBC : Java Database Connectivity JDBC : Java Database Connectivity
JDBC : Java Database Connectivity DevAdnani
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connectionPaneliya Prince
 

Similar to jdbc-130913021409-phpapp01000988www.pptx (20)

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 with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
JDBC Architecture and Drivers
JDBC Architecture and DriversJDBC Architecture and Drivers
JDBC Architecture and Drivers
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
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
 
Jdbc_ravi_2016
Jdbc_ravi_2016Jdbc_ravi_2016
Jdbc_ravi_2016
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Chapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxChapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptx
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
 
Core jdbc basics
Core jdbc basicsCore jdbc basics
Core jdbc basics
 
Jdbc driver types
Jdbc driver typesJdbc driver types
Jdbc driver types
 
JDBC : Java Database Connectivity
JDBC : Java Database Connectivity JDBC : Java Database Connectivity
JDBC : Java Database Connectivity
 
java 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptxjava 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptx
 
JDBC
JDBCJDBC
JDBC
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

jdbc-130913021409-phpapp01000988www.pptx

  • 1.
  • 2. Discussions ⦿What is JDBC? ⦿What is ODBC? ⦿JDBC vs ODBC? ⦿ Architecture of JDBC. ⦿ Types of JDBC driver available. ⦿ Steps to connect to DB. ⦿ Types of Statement.
  • 3. What is JDBC ? ⦿ JDBC acronym of Java Database connectivity; though Sun Microsystems ⦿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
  • 4.  JDBC is an interface between Java and Database  JDBC receives queries from Java Application program and communicate with Database  All the communications are in the form of SQL commands  JDBC is reponsible for  Open a Connection  Communicate with database  Execute SQL statements  Retrive query results What is JDBC ?
  • 5. Open DataBase Connectivity (ODBC)  Standard designed by Microsoft to interact with databases  ODBC is packed with many features and extending support for all type of databases  ODBC provides multiple mechanism for performing single task and number of data handling capabilities
  • 6. JDBC vs ODBC  JDBC and ODBC are X/OPEN call level interface for SQL  JDBC is not a derivative of ODBC  JDBC is compact and simple  JDBC is meant for simple access to the database and difficult task at least make possible
  • 8. JDBC Drivers  JDBC driver is responsible for making connection with different databases  It is also translating the queries received from Application and submit into database  A reverse translation is also required to perform by the Driver  JDBC Driver speaks JAVA to Application and native language to database  JDBC Drivers are exists for almost all databases  Appropriate driver will load for requied database
  • 9. 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.
  • 10. JDBC – ODBC Bridge  It is a JDBC driver designed to let Java application communicate with database via an underlying ODBC driver  It is called Type I JDBC connector  It can be used with multiple databases and is vendor independent  This type JDBC driver speaks only to ODBC driver, hence works for Databases supported by ODBC  One more added layer is used and hence more complex and slower than JDBC drivers
  • 11. Native-API-Partly-Java Driver  It make use of local native libraries to communicate with database  Vendor specific Call Level Interface(CLI) installed locally are used by this type driver  CLI libraries are actually communicate with database  Application level requests are translated into equallent native method call of CLI  Faster than Type I driver
  • 12. JDBC-Net-All-Java Driver  Type III Driver, uses the CLI libraries locates in a remote server  Type III driver has two major components  An All-Java portion that can download to the client  Server portion containing both Java and Native methods  All communication between Application and Database is 100% Java to Java  This type of driver is also depending on CLI calls, which is installed on Server  Type III can be used in Internet, since no direct access to CLI libraries  Type III Network protocol is not standardized
  • 13. Native-Protocol-All-Java Driver  100% java specific drivers  No intermediate translation is required  But all vendor specific driver cannot released by Java  Java Applets are now free from Acces restrictions
  • 14. Steps to connect? ⦿Define the connection URL. ⦿Established the connection. ⦿ Create the Statement object. ⦿Execute a query. ⦿Process the results. ⦿Close the connection.
  • 15. 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”);
  • 16. Steps to connect? ⦿ Established the connection: Connection con =DriverManager.getConnection(“url”,”user_name”,”pass”);
  • 17. Steps to connect? ⦿ Create the Statement object: Statement stmt=con.createStatement();
  • 18. 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);
  • 19. 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)); }
  • 20. Steps to connect? ⦿Close the connection release all the resources that the connection is holding. stmt.close(); con.close();
  • 21. Steps to connect? ⦿ Summarizing the steps for connecting java DB and inserting values in DB Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbac us","teddy","teddy"); Statement stmt=con.createStatement(); String sql=“INSERT INTO TEDDY(47,’jani’)”; stmt.executeUpdate(sql); stmt.close(); con.close();
  • 22. Types of Statement available ⦿There are three types of Statement available in Statement class:-  Statement  PreparedStatement  CallableStatement
  • 23. Types of Statement available ⦿Statement This represent a simple sql/mysql statement. Statement stmt=con.createStatement();
  • 24. 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();
  • 25. Types of Statement available ⦿CallableStatement This allows the access of stored procedures; that are stored on the database. CallableStatement csmt=con.prepareCall();