SlideShare a Scribd company logo
JDBC 4.0  New Features and Enhancements By Sharad Acharya Cabela’s Inc May 9, 2007
Goal of the presentation Describe and discuss JDBC4.0 APIs objectives new features  enhancements
Introduction New features and enhancements Code examples Key points Q/A Structure of this presentation
Introduction to JDBC Set of API's that allow Java programs to  Create, retrieve, delete and update RDBMS  Send SQL statements to underlying database and retrieve results
JDK and JDBC releases http://java.sun.com/j2se/codenames.html 9/2004 5.0(Tiger) 12/2006 4.0 6.0(Mustang) 7.0(Dolphin?) 2/2002 3.0 1.4(Merlin) 5/2000 1.3(Kestrel)  12/1998 2.0 1.2(Playground) 9/1997 1.0 1.1(Brutus, Chelsea…)  Date JDBC JDK(codename)
JDBC 4.0 Released with JSDK 6.0(AKA Mustang) Java Specification Request (JSR) 221 under Java Community Process(JCP).  Goals:  better object management support more data type support  flexible ease of use
JDBC 4.0 API Specification lists twenty new features or enhancements  Some are major: SQLXML data type Some are minor: a new free() method in Array interface New APIs provide access to commonly implemented features of SQL:2003
Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
What is new? Object management Exception handling Data type support API changes
Easy driver management ‘ Getting connected’ becomes easier Goodbye to Class.forName(“jdbc_class")  Welcome to automatic driver class loading DataSource object preferred way  promotes portability allows dynamic driver usage
Code snippet 1 Getting connection in Apache derby database DataSource ds = new EmbeddedDataSource40(); ds.setDatabaseName(“dbName”);  con = ds.getConnection();
More flexible   ResultSet   SQLXML data type support(4.0) RowSet : scrollable, updateable, offline editable ResultSet(3.0) WebRowSet : read data from database tables and serialize to XML document and vice versa (3.0)
Exception   handling Chained exception  Enhanced for loop support try {//some code that throw SQLException }  catch (SQLException ex) {  for(Throwable t : ex ) {  System.err.println("Error encountered: " + t);  }  }
Data type support New SQLXML data New RowId data Enhanced support for large object types
New SQLXML data type Mapping in the Java programming language for the XML data type in SQL  Stores an XML value in a table column Implemented as a logical pointer to the XML data valid for the duration of the transaction in which it was created
Code snippet 2 con = ds.getConnection();  SQLXML sx= con.createSQLXML(); sx.setString(“Catalog");  String psx ="insert into "+tableName+  " ( orderNo, orderType) values(?,?) ";  PreparedStatement pstmt = con.prepareStatement(psx); pstmt.setString(1,“1122344");  pstmt.setSQLXML(2,sx);  pstmt.executeUpdate();
Scenario: Order entry system JMS integration, XML for message exchange Substantial code to convert data from/to XML <Legacy> Order entry <database> Oracle I N T E G R A T I O N <Legacy> Inventory Management <Legacy> Order dispatch <J2EE TX>  Order process JDBC
Code snippet 3.1 Document doc= Util.createDoc(…) String queryString = “select id, orderNo from…”; String orderNo=rs.getString(2); Element ele = Util.createElement(…); //…. Prepare the xml(6 more lines) Util.appendChild(doc, ele); //client code 15 lines
Code snippet 3.2 SQLXML SQLXML sqlxml = rs.getSQLXML(column); InputStream bis = sqlxml.getBinaryStream();  DocumentBuilder parser = DocumentBuilderFactory.newInstance(). newDocumentBuilder();  Document doc = parser.parse(binaryStream);
RowId class SQL ROWID identifies a row within a table and is the fastest way to access it.  A new RowId interface provides access to ROWID SQL type from a Java class.
Large objects CLOB, BOLB, ARRAY and STRUCT  Interface Clob, Blob, Array and Struct were added on Version 2.0 of JDBC More methods added in version 4.0 for large object manipulation
API changes Array  Connection DatabaseMetaData NCS support Scalar Functions Statement and its sub interfaces Wrapper
Array The mapping in the Java programming language for the SQL type ARRAY  Since JDK 1.2 JDBC 4.0 adds a new free() method
Connection Several create methods createClob, createBlob to create large objects in Connection interface.  Method to register/deregister StatementEventListener in PooledConnection interface
DatabaseMetaData Code portability issues Need interface to query database capabilities, if provided Example: CREATE TABLE getTypeInfo may be called to find out if a feature is supported before issuing an execute command
Code snippet 3 List database schemas under a catalog that match a pattern(new in JDBC 4.0) con = ds.getConnection(); DatabaseMetaData dmd = con.getMetaData(); rs=dmd.getSchemas( &quot;TABLE_CAT&quot;,&quot;SYS%&quot;);
Portability Backward compatible
National Character Set(NCS) SQL:2003 provides support for SQL types of NCHAR, NVARCHAR, LONGNVARCHAR and NCLOB Choose NCS if data need extensive character processing operations JDBC 4.0 provides NCS support
API to support NCS Setter and update methods in PreparedStatement and CallableStatement Setter methods in ResultSet eg, setNString, setNClob Read and write methods in SQLInput and SQLOuput, eg readNClob, writeNClob, readNString,  writeNString
Scalar Function Operates on some input and returns some result : abs(number) Used in SQL query from Java code JDBC 4.0 supports for additional scalar functions: CHAR_LENGTH, CHARACTER_LENGTH, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, EXTRACT, OCTET_LENGTH, POSITION
Statements Statement isClosed, setPoolable, isPoolable PreparedStatement and CallableStatement:  more methods to insert large objects using InputStream and Reader
Wrapper Vendors may wrap implementation of JDBC driver for architectural reason provide standard access to wrapped resource Implemented as Adapter Pattern
Using Wrapper New interface in JDBC 4.0 Use isWrappedFor(Class<?> iface) to check if the class that implements this interface is either direct or indirect wrapper for an object find out an object that implements the given interface by unwrap(Class  <T> iface)
Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
Example1 Retrieving connection Previous versions vs Version 4.0
Example2 Exception handling in previous versions vs this Version
Example3: SQLXML SQLXML new interface SQLXML SQL type
Example4 DatabaseMetaData  What was available What has been added
Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
Key Points Programming ease and flexibility &quot;Getting Connected&quot; becomes easier Using JDBC objects becomes more flexible More API’s become available
Key Points Automatic loading of JDBC Driver SQL:2003 support including SQLXML NCS support Enhanced support for large objects SQLException enhancement
Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
Ad

More Related Content

What's hot (20)

ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
Randy Connolly
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
Marco Gralike
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
Svetlin Nakov
 
Ado.net
Ado.netAdo.net
Ado.net
Iblesoft
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
Marco Gralike
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
rchakra
 
Ado.net
Ado.netAdo.net
Ado.net
pacatarpit
 
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file serverBGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
Marco Gralike
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
For Beginners - Ado.net
For Beginners - Ado.netFor Beginners - Ado.net
For Beginners - Ado.net
Tarun Jain
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
Anekwong Yoddumnern
 
Ado.net
Ado.netAdo.net
Ado.net
dina1985vlr
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Farzad Wadia
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
Luis Goldster
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Oracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New FeaturesOracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 
Ado .net
Ado .netAdo .net
Ado .net
Manish Singh
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
mentorrbuddy
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
Marco Gralike
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
Svetlin Nakov
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
Marco Gralike
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
rchakra
 
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file serverBGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
Marco Gralike
 
For Beginners - Ado.net
For Beginners - Ado.netFor Beginners - Ado.net
For Beginners - Ado.net
Tarun Jain
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
Luis Goldster
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Oracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New FeaturesOracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 

Similar to Jdbc 4.0 New Features And Enhancements (20)

jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
Dr. Ramkumar Lakshminarayanan
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
IMC Institute
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
Harshit Choudhary
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
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
Fulvio Corno
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
IMC Institute
 
Jdbc
JdbcJdbc
Jdbc
smvdurajesh
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
5.C#
5.C#5.C#
5.C#
Raghu nath
 
Jdbc
JdbcJdbc
Jdbc
Indu Lata
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
David Truxall
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
Fulvio Corno
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
Fulvio Corno
 
JDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each DriverJDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
JDBC
JDBCJDBC
JDBC
Balwinder Kumar
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
Rajarajan Sadhasivam
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
4. Database Connectivity using JDBC .ppt
4. Database Connectivity using JDBC .ppt4. Database Connectivity using JDBC .ppt
4. Database Connectivity using JDBC .ppt
HITENKHEMANI
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
IMC Institute
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
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
Fulvio Corno
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
IMC Institute
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
David Truxall
 
JDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each DriverJDBC DriversPros and Cons of Each Driver
JDBC DriversPros and Cons of Each Driver
10300PEDDIKISHOR
 
4. Database Connectivity using JDBC .ppt
4. Database Connectivity using JDBC .ppt4. Database Connectivity using JDBC .ppt
4. Database Connectivity using JDBC .ppt
HITENKHEMANI
 
Ad

Jdbc 4.0 New Features And Enhancements

  • 1. JDBC 4.0 New Features and Enhancements By Sharad Acharya Cabela’s Inc May 9, 2007
  • 2. Goal of the presentation Describe and discuss JDBC4.0 APIs objectives new features enhancements
  • 3. Introduction New features and enhancements Code examples Key points Q/A Structure of this presentation
  • 4. Introduction to JDBC Set of API's that allow Java programs to Create, retrieve, delete and update RDBMS Send SQL statements to underlying database and retrieve results
  • 5. JDK and JDBC releases http://java.sun.com/j2se/codenames.html 9/2004 5.0(Tiger) 12/2006 4.0 6.0(Mustang) 7.0(Dolphin?) 2/2002 3.0 1.4(Merlin) 5/2000 1.3(Kestrel) 12/1998 2.0 1.2(Playground) 9/1997 1.0 1.1(Brutus, Chelsea…) Date JDBC JDK(codename)
  • 6. JDBC 4.0 Released with JSDK 6.0(AKA Mustang) Java Specification Request (JSR) 221 under Java Community Process(JCP). Goals: better object management support more data type support flexible ease of use
  • 7. JDBC 4.0 API Specification lists twenty new features or enhancements Some are major: SQLXML data type Some are minor: a new free() method in Array interface New APIs provide access to commonly implemented features of SQL:2003
  • 8. Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
  • 9. What is new? Object management Exception handling Data type support API changes
  • 10. Easy driver management ‘ Getting connected’ becomes easier Goodbye to Class.forName(“jdbc_class&quot;) Welcome to automatic driver class loading DataSource object preferred way promotes portability allows dynamic driver usage
  • 11. Code snippet 1 Getting connection in Apache derby database DataSource ds = new EmbeddedDataSource40(); ds.setDatabaseName(“dbName”); con = ds.getConnection();
  • 12. More flexible ResultSet SQLXML data type support(4.0) RowSet : scrollable, updateable, offline editable ResultSet(3.0) WebRowSet : read data from database tables and serialize to XML document and vice versa (3.0)
  • 13. Exception handling Chained exception Enhanced for loop support try {//some code that throw SQLException } catch (SQLException ex) { for(Throwable t : ex ) { System.err.println(&quot;Error encountered: &quot; + t); } }
  • 14. Data type support New SQLXML data New RowId data Enhanced support for large object types
  • 15. New SQLXML data type Mapping in the Java programming language for the XML data type in SQL Stores an XML value in a table column Implemented as a logical pointer to the XML data valid for the duration of the transaction in which it was created
  • 16. Code snippet 2 con = ds.getConnection(); SQLXML sx= con.createSQLXML(); sx.setString(“Catalog&quot;); String psx =&quot;insert into &quot;+tableName+ &quot; ( orderNo, orderType) values(?,?) &quot;; PreparedStatement pstmt = con.prepareStatement(psx); pstmt.setString(1,“1122344&quot;); pstmt.setSQLXML(2,sx); pstmt.executeUpdate();
  • 17. Scenario: Order entry system JMS integration, XML for message exchange Substantial code to convert data from/to XML <Legacy> Order entry <database> Oracle I N T E G R A T I O N <Legacy> Inventory Management <Legacy> Order dispatch <J2EE TX> Order process JDBC
  • 18. Code snippet 3.1 Document doc= Util.createDoc(…) String queryString = “select id, orderNo from…”; String orderNo=rs.getString(2); Element ele = Util.createElement(…); //…. Prepare the xml(6 more lines) Util.appendChild(doc, ele); //client code 15 lines
  • 19. Code snippet 3.2 SQLXML SQLXML sqlxml = rs.getSQLXML(column); InputStream bis = sqlxml.getBinaryStream(); DocumentBuilder parser = DocumentBuilderFactory.newInstance(). newDocumentBuilder(); Document doc = parser.parse(binaryStream);
  • 20. RowId class SQL ROWID identifies a row within a table and is the fastest way to access it. A new RowId interface provides access to ROWID SQL type from a Java class.
  • 21. Large objects CLOB, BOLB, ARRAY and STRUCT Interface Clob, Blob, Array and Struct were added on Version 2.0 of JDBC More methods added in version 4.0 for large object manipulation
  • 22. API changes Array Connection DatabaseMetaData NCS support Scalar Functions Statement and its sub interfaces Wrapper
  • 23. Array The mapping in the Java programming language for the SQL type ARRAY Since JDK 1.2 JDBC 4.0 adds a new free() method
  • 24. Connection Several create methods createClob, createBlob to create large objects in Connection interface. Method to register/deregister StatementEventListener in PooledConnection interface
  • 25. DatabaseMetaData Code portability issues Need interface to query database capabilities, if provided Example: CREATE TABLE getTypeInfo may be called to find out if a feature is supported before issuing an execute command
  • 26. Code snippet 3 List database schemas under a catalog that match a pattern(new in JDBC 4.0) con = ds.getConnection(); DatabaseMetaData dmd = con.getMetaData(); rs=dmd.getSchemas( &quot;TABLE_CAT&quot;,&quot;SYS%&quot;);
  • 28. National Character Set(NCS) SQL:2003 provides support for SQL types of NCHAR, NVARCHAR, LONGNVARCHAR and NCLOB Choose NCS if data need extensive character processing operations JDBC 4.0 provides NCS support
  • 29. API to support NCS Setter and update methods in PreparedStatement and CallableStatement Setter methods in ResultSet eg, setNString, setNClob Read and write methods in SQLInput and SQLOuput, eg readNClob, writeNClob, readNString, writeNString
  • 30. Scalar Function Operates on some input and returns some result : abs(number) Used in SQL query from Java code JDBC 4.0 supports for additional scalar functions: CHAR_LENGTH, CHARACTER_LENGTH, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, EXTRACT, OCTET_LENGTH, POSITION
  • 31. Statements Statement isClosed, setPoolable, isPoolable PreparedStatement and CallableStatement: more methods to insert large objects using InputStream and Reader
  • 32. Wrapper Vendors may wrap implementation of JDBC driver for architectural reason provide standard access to wrapped resource Implemented as Adapter Pattern
  • 33. Using Wrapper New interface in JDBC 4.0 Use isWrappedFor(Class<?> iface) to check if the class that implements this interface is either direct or indirect wrapper for an object find out an object that implements the given interface by unwrap(Class <T> iface)
  • 34. Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
  • 35. Example1 Retrieving connection Previous versions vs Version 4.0
  • 36. Example2 Exception handling in previous versions vs this Version
  • 37. Example3: SQLXML SQLXML new interface SQLXML SQL type
  • 38. Example4 DatabaseMetaData What was available What has been added
  • 39. Introduction New features and enhancements Examples Key points Q/A Structure of this presentation
  • 40. Key Points Programming ease and flexibility &quot;Getting Connected&quot; becomes easier Using JDBC objects becomes more flexible More API’s become available
  • 41. Key Points Automatic loading of JDBC Driver SQL:2003 support including SQLXML NCS support Enhanced support for large objects SQLException enhancement
  • 42. Introduction New features and enhancements Examples Key points Q/A Structure of this presentation

Editor's Notes

  • #2: The first slide