SlideShare uma empresa Scribd logo
1 de 40
JDBC – J ava  D ata b ase  C onnectivity Modified slides  from Dr. Yehoshua Sagiv
Introduction to JDBC ,[object Object],[object Object],[object Object],[object Object]
JDBC Architecture Java Application JDBC Oracle DB2 MySQL Oracle  Driver DB2 Driver MySQL  Driver Network We will  use this one…
JDBC Architecture (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],Application JDBC Driver
JDBC Driver for Oracle ,[object Object],[object Object]
Seven Steps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Loading the Driver ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
An Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],imaginary1 imaginary2 Registered Drivers MySQL
Connecting to the Database ,[object Object],[object Object],[object Object]
Connecting to the Database ,[object Object],[object Object],imaginary1 imaginary2 Registered Drivers Oracle    acceptsURL( "jdbc:imaginaryDB1" )? ,[object Object]
Interaction with the Database ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Querying with Statement ,[object Object],[object Object],String  queryStr  =  "SELECT * FROM employee "   + "WHERE lname = ‘Wong'" ; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery( queryStr );
Changing DB with Statement String  deleteStr  =  "DELETE FROM employee "   + "WHERE lname = ‘Wong'" ; Statement stmt = con.createStatement(); int delnum = stmt.executeUpdate( deleteStr ); ,[object Object],[object Object]
About Prepared Statements ,[object Object],[object Object],[object Object],[object Object],[object Object]
Querying with  PreparedStatement String  queryStr  =  "SELECT * FROM employee "   + "WHERE superssn=  ?  and salary >  ? " ; PreparedStatement pstmt =  con.prepareStatement( queryStr ); pstmt.setString( 1 ,   "333445555" ); pstmt.setInt( 2 , 26000); ResultSet rs = pstmt.executeQuery();
Updating with  PreparedStatement String deleteStr =  “ DELETE FROM employee "   + "WHERE superssn = ? and salary > ?" ;   PreparedStatement pstmt =  con.prepareStatement(deleteStr); pstmt.setString(1,  "333445555" ); pstmt.setDouble(2, 26000); int delnum = pstmt.executeUpdate();
Statements vs. PreparedStatements: Be Careful! ,[object Object],String  val  =   "abc" ; PreparedStatement pstmt =  con.prepareStatement( "select * from R where A=?" ); pstmt.setString(1,  val ); ResultSet rs =  pstmt.executeQuery(); String val =   "abc" ; Statement stmt =  con.createStatement( ); ResultSet rs =  stmt.executeQuery( "select * from R where A="  + val);
Statements vs. PreparedStatements: Be Careful! ,[object Object],[object Object],PreparedStatement pstmt =  con.prepareStatement( "select * from ?" ); pstmt.setString(1, myFavoriteTableString);
Timeout ,[object Object],[object Object],[object Object]
ResultSet ,[object Object],[object Object],[object Object],[object Object],[object Object]
ResultSet Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ResultSet Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ResultSet Methods ,[object Object]
ResultSet Example Statement stmt = con.createStatement(); ResultSet  rs  = stmt.  executeQuery( "select lname,salary from employees" );      // Print the result while ( rs .next()) {  System.out.print(rs.getString(1) +  ":" );  System.out.println(rs.getDouble( “salary" )); }
Mapping Java Types to SQL Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Null Values ,[object Object],[object Object],[object Object],[object Object],[object Object]
Null Values ,[object Object],[object Object],[object Object]
ResultSet Meta-Data  ResultSetMetaData  rsmd  = rs.getMetaData(); int  numcols  =  rsmd .getColumnCount(); for (int i = 1 ; i <=  numcols ; i++) { System.out.print( rsmd .getColumnLabel(i)+ &quot; &quot; ); } A  ResultSetMetaData  is an object that can be used to get information about the properties of the columns in a  ResultSet  object An example: write the columns of the result set
Database Time ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cleaning Up After Yourself ,[object Object],con.close(); stmt.close(); pstmt.close(); rs.close()
Dealing With Exceptions ,[object Object],catch (SQLException e) { while (e != null) { System.out.println(e.getSQLState()); System.out.println(e.getMessage()); System.out.println(e.getErrorCode()); e = e.getNextException(); } }
Transactions and JDBC ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example ,[object Object],PreparedStatement pstmt =  con.prepareStatement( &quot;update BankAccount    set amount = amount + ?   where accountId = ?&quot; ); pstmt.setInt(1,-100);  pstmt.setInt(2, 13); pstmt.executeUpdate(); pstmt.setInt(1, 100);  pstmt.setInt(2, 72); pstmt.executeUpdate(); What happens if this update fails?
Transaction Management ,[object Object],[object Object],[object Object],[object Object],[object Object]
AutoCommit ,[object Object],[object Object],[object Object],setAutoCommit( boolean val )
Scrollable ResultSet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scrollable ResultSet (cont’d) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scrollable ResultSet (cont’d) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scrollable ResultSet (cont’d) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JDBC Usage in Industry ,[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados (20)

Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Java Lambda Expressions.pptx
Java Lambda Expressions.pptxJava Lambda Expressions.pptx
Java Lambda Expressions.pptx
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Java Beans
Java BeansJava Beans
Java Beans
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
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)
 
Java swing
Java swingJava swing
Java swing
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Jdbc
JdbcJdbc
Jdbc
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Java I/O
Java I/OJava I/O
Java I/O
 

Destaque

JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database ConnectivityRanjan Kumar
 
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 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 MySqlkamal kotecha
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servletsNuha Noor
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBCDudy Ali
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivitybackdoor
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comphanleson
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Som Prakash Rai
 
Java Swing
Java SwingJava Swing
Java SwingShraddha
 
Java JDBC Communication and Connection Manager
Java JDBC Communication and Connection ManagerJava JDBC Communication and Connection Manager
Java JDBC Communication and Connection Manageraashish
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQLAdil Mehmoood
 

Destaque (20)

JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
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
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Jdbc
JdbcJdbc
Jdbc
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
java Jdbc
java Jdbc java Jdbc
java Jdbc
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
Jdbc in java
Jdbc in javaJdbc in java
Jdbc in java
 
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)
 
Java Swing
Java SwingJava Swing
Java Swing
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Java lezione 10
Java lezione 10Java lezione 10
Java lezione 10
 
Java JDBC Communication and Connection Manager
Java JDBC Communication and Connection ManagerJava JDBC Communication and Connection Manager
Java JDBC Communication and Connection Manager
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 

Semelhante a JDBC – Java Database Connectivity

Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Databasejitendral
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCOUM SAOKOSAL
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.pptSwapnil Kale
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsFulvio Corno
 

Semelhante a JDBC – Java Database Connectivity (20)

Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
JDBC (2).ppt
JDBC (2).pptJDBC (2).ppt
JDBC (2).ppt
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
Lecture17
Lecture17Lecture17
Lecture17
 
jdbc
jdbcjdbc
jdbc
 

Mais de Information Technology (20)

Web303
Web303Web303
Web303
 
Sql Server Security Best Practices
Sql Server Security Best PracticesSql Server Security Best Practices
Sql Server Security Best Practices
 
SAN
SANSAN
SAN
 
SAN Review
SAN ReviewSAN Review
SAN Review
 
SQL 2005 Disk IO Performance
SQL 2005 Disk IO PerformanceSQL 2005 Disk IO Performance
SQL 2005 Disk IO Performance
 
RAID Review
RAID ReviewRAID Review
RAID Review
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 
Sql 2005 high availability
Sql 2005 high availabilitySql 2005 high availability
Sql 2005 high availability
 
IIS 7: The Administrator’s Guide
IIS 7: The Administrator’s GuideIIS 7: The Administrator’s Guide
IIS 7: The Administrator’s Guide
 
MOSS 2007 Deployment Fundamentals -Part2
MOSS 2007 Deployment Fundamentals -Part2MOSS 2007 Deployment Fundamentals -Part2
MOSS 2007 Deployment Fundamentals -Part2
 
MOSS 2007 Deployment Fundamentals -Part1
MOSS 2007 Deployment Fundamentals -Part1MOSS 2007 Deployment Fundamentals -Part1
MOSS 2007 Deployment Fundamentals -Part1
 
Clustering and High Availability
Clustering and High Availability Clustering and High Availability
Clustering and High Availability
 
F5 beyond load balancer (nov 2009)
F5 beyond load balancer (nov 2009)F5 beyond load balancer (nov 2009)
F5 beyond load balancer (nov 2009)
 
WSS 3.0 & SharePoint 2007
WSS 3.0 & SharePoint 2007WSS 3.0 & SharePoint 2007
WSS 3.0 & SharePoint 2007
 
SharePoint Topology
SharePoint Topology SharePoint Topology
SharePoint Topology
 
Sharepoint Deployments
Sharepoint DeploymentsSharepoint Deployments
Sharepoint Deployments
 
Microsoft Clustering
Microsoft ClusteringMicrosoft Clustering
Microsoft Clustering
 
Scalable Internet Servers and Load Balancing
Scalable Internet Servers and Load BalancingScalable Internet Servers and Load Balancing
Scalable Internet Servers and Load Balancing
 
Web Hacking
Web HackingWeb Hacking
Web Hacking
 
Migration from ASP to ASP.NET
Migration from ASP to ASP.NETMigration from ASP to ASP.NET
Migration from ASP to ASP.NET
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

JDBC – Java Database Connectivity

  • 1. JDBC – J ava D ata b ase C onnectivity Modified slides from Dr. Yehoshua Sagiv
  • 2.
  • 3. JDBC Architecture Java Application JDBC Oracle DB2 MySQL Oracle Driver DB2 Driver MySQL Driver Network We will use this one…
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Querying with PreparedStatement String queryStr = &quot;SELECT * FROM employee &quot; + &quot;WHERE superssn= ? and salary > ? &quot; ; PreparedStatement pstmt = con.prepareStatement( queryStr ); pstmt.setString( 1 , &quot;333445555&quot; ); pstmt.setInt( 2 , 26000); ResultSet rs = pstmt.executeQuery();
  • 16. Updating with PreparedStatement String deleteStr = “ DELETE FROM employee &quot; + &quot;WHERE superssn = ? and salary > ?&quot; ; PreparedStatement pstmt = con.prepareStatement(deleteStr); pstmt.setString(1, &quot;333445555&quot; ); pstmt.setDouble(2, 26000); int delnum = pstmt.executeUpdate();
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. ResultSet Example Statement stmt = con.createStatement(); ResultSet  rs  = stmt. executeQuery( &quot;select lname,salary from employees&quot; );      // Print the result while ( rs .next()) {  System.out.print(rs.getString(1) +  &quot;:&quot; );  System.out.println(rs.getDouble( “salary&quot; )); }
  • 25.
  • 26.
  • 27.
  • 28. ResultSet Meta-Data ResultSetMetaData rsmd = rs.getMetaData(); int numcols = rsmd .getColumnCount(); for (int i = 1 ; i <= numcols ; i++) { System.out.print( rsmd .getColumnLabel(i)+ &quot; &quot; ); } A ResultSetMetaData is an object that can be used to get information about the properties of the columns in a ResultSet object An example: write the columns of the result set
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.

Notas do Editor

  1. Lobs and DDL