SlideShare a Scribd company logo
Introduction to JDBC
Michelle Lee, Ye Wu & Jeff Offutt
http://www.cs.gmu.edu/~offutt/
SWE 432
Design and Implementation of Software for the Web
5/24/2023 © Wu, Lee & Offutt 2
JDBC
• JDBC (Java Database Connectivity) API allows Java
programs to connect to databases
• Database access is the same for all database vendors
• The JVM uses a JDBC driver to translate generalized
JDBC calls into vendor specific database calls
• There are four general types of JDBC drivers
– We will look at Type 4 …
5/24/2023 © Wu, Lee & Offutt 3
Pure Java Driver (Type 4)
• These drivers convert the JDBC API calls to direct
network calls using vendor-specific networking protocols
by making direct socket connections with the database
• It is the most efficient method to access database, both in
performance and development time
• It is the simplest to deploy
• All major database vendors provide pure Java JDBC
drivers for their databases and they are also available from
third party vendors
• For a list of JDBC drivers, refer to
– http://industry.java.sun.com/products/jdbc/drivers
5/24/2023 © Wu, Lee & Offutt 4
Java
Application
DB Client
Pure Java Driver (2)
JDBC
API
JDBC Driver
Data Source
Server
5/24/2023 © Wu, Lee & Offutt 5
Typical JDBC Programming Procedure
1. Load the database driver
2. Obtain a connection
3. Create and execute statements (SQL queries)
4. Use result sets (tables) to navigate through the results
5. Close the connection
5/24/2023 © Wu, Lee & Offutt 6
Driver Manager
• The purpose of the java.sql.DriverManger class in
JDBC is to provide a common access layer on top of
different database drivers used in an application
• DriverManager requires that each driver required by the
application must be registered before use, so that the
DriverManager is aware of it
• Load the database driver using ClassLoader :
– Class.forName (“oracle.jdbc.driver.OracleDriver”);
5/24/2023 © Wu, Lee & Offutt 7
Connecting to a Database
• Type 4 JDBC Driver – Oracle Server
Class.forName (“oracle.jdbc.driver.OracleDriver”);
con = DriverManager.getConnection (
“jdbc:oracle:thin:@bonsai.ite.gmu.edu:1521:ite”,
“accountname", “password”);
• Type 4 JDBC Driver – MySQL Server
Class.forName (“org.gjt.mm.mysql.Driver”);
con = DriverManager.getConnection
(“jdbc:mysql://localhost/databasename”, uid, passwd);
5/24/2023 © Wu, Lee & Offutt 8
Creating Tables
• Creating a Coffee table
CREATE TABLE COFFEES (COF_NAME VARCHAR(32), SUP_ID
INTEGER, PRICE FLOAT, SALES INTEGER, TOTAL INTEGER)
• Creating JDBC statements
Statement stmt = con.createStatement ();
• Execute a statement
stmt.executeUpdate (“CREATE TABLE COFFEES “ +
“(COF_NAME VARCHAR(32), SUP_ID INTEGER,
PRICE FLOAT, “ + “SALES INTEGER, TOTAL
INTEGER)”);
SQL query
5/24/2023 © Wu, Lee & Offutt 9
Execute Statements
• This uses executeUpdate because the SQL statement
contained in createTableCoffees is a DDL (data
definition language) statement
• Statements that create a table, alter a table, or drop a table
are all examples of DDL statements and are executed with
the method executeUpdate
• executeUpdate is also used to execute SQL statements
that update a table
5/24/2023 © Wu, Lee & Offutt 10
Execute Statements
• In practice, executeUpdate is used far more often to
update tables than it is to create them because a table is
created once but may be updated many times
• The method used most often for executing SQL statements
is executeQuery
• executeQuery is used to execute SELECT statements,
which comprise the vast majority of SQL statements
5/24/2023 © Wu, Lee & Offutt 11
Entering Data into a Table
Statement stmt = con.createStatement();
stmt.executeUpdate ( "INSERT INTO COFFEES " +
"VALUES ('Colombian', 101, 7.99, 0, 0)");
stmt.executeUpdate ( "INSERT INTO COFFEES " +
"VALUES ('French_Roast', 49, 8.99, 0, 0)" );
stmt.executeUpdate ( "INSERT INTO COFFEES " +
"VALUES ('Espresso', 150, 9.99, 0, 0)" );
stmt.executeUpdate ( "INSERT INTO COFFEES " +
"VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)" );
stmt.executeUpdate ( "INSERT INTO COFFEES " +
"VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)" );
5/24/2023 © Wu, Lee & Offutt 12
Getting Data From a Table
ResultSet rs = stmt.executeQuery ("SELECT COF_NAME, PRICE
FROM COFFEES");
while (rs.next())
{
String s = rs.getString ("COF_NAME");
float n = rs.getFloat ("PRICE");
System.out.println (s + " " + n);
}
5/24/2023 © Wu, Lee & Offutt 13
JNDI
Connection Manager
JDBC Data Source Architecture
Application JDBC Database
5/24/2023 © Wu, Lee & Offutt 14
Sample code
• Sun JDBC tutorial

More Related Content

Similar to JDBC.ppt

JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
Jayaprasanna4
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
Nuha Noor
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
Hendrik Ebbers
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
arikazukito
 
Weblogic 101 for dba
Weblogic  101 for dbaWeblogic  101 for dba
Weblogic 101 for dba
Osama Mustafa
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
java.pptx
java.pptxjava.pptx
java.pptx
bfgd1
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
Simba Technologies
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
SachinSingh217687
 
A to z for sql azure databases
A to z for sql azure databasesA to z for sql azure databases
A to z for sql azure databases
Antonios Chatzipavlis
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Jdbc
JdbcJdbc

Similar to JDBC.ppt (20)

JDBC
JDBCJDBC
JDBC
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
jdbc
jdbcjdbc
jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
Weblogic 101 for dba
Weblogic  101 for dbaWeblogic  101 for dba
Weblogic 101 for dba
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
A to z for sql azure databases
A to z for sql azure databasesA to z for sql azure databases
A to z for sql azure databases
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Jdbc
JdbcJdbc
Jdbc
 

Recently uploaded

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
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
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 

Recently uploaded (20)

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
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
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 

JDBC.ppt

  • 1. Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt http://www.cs.gmu.edu/~offutt/ SWE 432 Design and Implementation of Software for the Web
  • 2. 5/24/2023 © Wu, Lee & Offutt 2 JDBC • JDBC (Java Database Connectivity) API allows Java programs to connect to databases • Database access is the same for all database vendors • The JVM uses a JDBC driver to translate generalized JDBC calls into vendor specific database calls • There are four general types of JDBC drivers – We will look at Type 4 …
  • 3. 5/24/2023 © Wu, Lee & Offutt 3 Pure Java Driver (Type 4) • These drivers convert the JDBC API calls to direct network calls using vendor-specific networking protocols by making direct socket connections with the database • It is the most efficient method to access database, both in performance and development time • It is the simplest to deploy • All major database vendors provide pure Java JDBC drivers for their databases and they are also available from third party vendors • For a list of JDBC drivers, refer to – http://industry.java.sun.com/products/jdbc/drivers
  • 4. 5/24/2023 © Wu, Lee & Offutt 4 Java Application DB Client Pure Java Driver (2) JDBC API JDBC Driver Data Source Server
  • 5. 5/24/2023 © Wu, Lee & Offutt 5 Typical JDBC Programming Procedure 1. Load the database driver 2. Obtain a connection 3. Create and execute statements (SQL queries) 4. Use result sets (tables) to navigate through the results 5. Close the connection
  • 6. 5/24/2023 © Wu, Lee & Offutt 6 Driver Manager • The purpose of the java.sql.DriverManger class in JDBC is to provide a common access layer on top of different database drivers used in an application • DriverManager requires that each driver required by the application must be registered before use, so that the DriverManager is aware of it • Load the database driver using ClassLoader : – Class.forName (“oracle.jdbc.driver.OracleDriver”);
  • 7. 5/24/2023 © Wu, Lee & Offutt 7 Connecting to a Database • Type 4 JDBC Driver – Oracle Server Class.forName (“oracle.jdbc.driver.OracleDriver”); con = DriverManager.getConnection ( “jdbc:oracle:thin:@bonsai.ite.gmu.edu:1521:ite”, “accountname", “password”); • Type 4 JDBC Driver – MySQL Server Class.forName (“org.gjt.mm.mysql.Driver”); con = DriverManager.getConnection (“jdbc:mysql://localhost/databasename”, uid, passwd);
  • 8. 5/24/2023 © Wu, Lee & Offutt 8 Creating Tables • Creating a Coffee table CREATE TABLE COFFEES (COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER, TOTAL INTEGER) • Creating JDBC statements Statement stmt = con.createStatement (); • Execute a statement stmt.executeUpdate (“CREATE TABLE COFFEES “ + “(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, “ + “SALES INTEGER, TOTAL INTEGER)”); SQL query
  • 9. 5/24/2023 © Wu, Lee & Offutt 9 Execute Statements • This uses executeUpdate because the SQL statement contained in createTableCoffees is a DDL (data definition language) statement • Statements that create a table, alter a table, or drop a table are all examples of DDL statements and are executed with the method executeUpdate • executeUpdate is also used to execute SQL statements that update a table
  • 10. 5/24/2023 © Wu, Lee & Offutt 10 Execute Statements • In practice, executeUpdate is used far more often to update tables than it is to create them because a table is created once but may be updated many times • The method used most often for executing SQL statements is executeQuery • executeQuery is used to execute SELECT statements, which comprise the vast majority of SQL statements
  • 11. 5/24/2023 © Wu, Lee & Offutt 11 Entering Data into a Table Statement stmt = con.createStatement(); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Colombian', 101, 7.99, 0, 0)"); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('French_Roast', 49, 8.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Espresso', 150, 9.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)" );
  • 12. 5/24/2023 © Wu, Lee & Offutt 12 Getting Data From a Table ResultSet rs = stmt.executeQuery ("SELECT COF_NAME, PRICE FROM COFFEES"); while (rs.next()) { String s = rs.getString ("COF_NAME"); float n = rs.getFloat ("PRICE"); System.out.println (s + " " + n); }
  • 13. 5/24/2023 © Wu, Lee & Offutt 13 JNDI Connection Manager JDBC Data Source Architecture Application JDBC Database
  • 14. 5/24/2023 © Wu, Lee & Offutt 14 Sample code • Sun JDBC tutorial