SlideShare a Scribd company logo
Open Connectivity
BI, Integration, and Apps on Couchbase using ODBC and
JDBC
June, 2015
• Who I am
• Driver(s) Overview
• Relational Model
• Demos
• ODBC in-depth
• JDBC in-depth
• QA
Contents
• Worked in the data access space for eight years and counting
• ODBC, OLEDB, JDBC, ADO.NET, ODBO, XMLA
• Core developer for the current generation of Simba’s data
access technologies
• Collaborated at an Engineering Level with Simba ISV
Customers to design and implement data drivers that are
today being shipped world wide
Kyle at a glance
• Simba connects people to data.
• HQ’ed in Vancouver, BC.
• 100ish employees.
• Founded in 1991.
• In 1992, Simba co-authored the original ODBC standard with Microsoft.
• Simba produces the SimbaEngine® SDK and drivers for the leading data
sources on multiple platforms.
Simba Technologies at a glance
Simba Technologies at a glance
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
• Partnership to create read/write ODBC and JDBC drivers
• ODBC 3.80
• JDBC 4.0 and 4.1
• Allow easy access to data within Couchbase from your
favourite BI and ETL tools
Why is Simba here?
What is an
ODBC / JDBC
Driver?
N1QL mode to allow
easy and advanced
analytics
• Couchbase is NoSQL
• Dynamic schema, documents vary within a bucket
• ODBC and JDBC are SQL
• Expect a fixed schema, each column is one type
• Must map from dynamic schema data to fixed schema data
Schema(less)
• SQL
• Catalog, Schema, Table
• Couchbase
• Namespace, Keyspace
Schema => Namespace
Table => Keyspace (sort of)
Relational Mapping
http://www.prabathsl.com/2013/02/document-oriented-database_14.html
Sample JSON Document:
{“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]}
Simple Flattening
Id Name Values[0] Values[1]
1 Couchbase V1 V2
Sample JSON Document:
{“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]}
Parent
Child
Re-Normalization
Id Name
1 Couchbase
Id Index Value
1 0 V1
1 1 V2
Demos
• C API
• Versions: 2.x, 3.0, 3.52, 3.80, etc…
• Non-Windows platforms are ODBC 3.52
• Driver Managers
• Windows, iODBC, unixODBC, etc…
• All functions have return codes
• SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, etc…
ODBC Technicals
• SQLHENV, SQLHDBC, SQLHSTMT, SQLHDESC
• Relationship is one-to-many
ODBC: Handles
• Allocate with SQLAllocHandle, free with SQLFreeHandle
• Ensure you set the version of ODBC in use
SQLSetEnvAttr(
hEnv,
SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3_80,
SQL_IS_INTEGER)
ODBC: Environment
• Allocate with SQLAllocHandle, created from SQLHENV
• Maintains the actual connection to Couchbase
• Create child statement objects to do work
• Disconnect with SQLDisconnect, free with SQLFreeHandle
ODBC: Connection
Open a connection using SQLDriverConnect
SQLDriverConnect(
hDbc,
windowHandle,
connStr, SQL_NTS, connStrLen
&outStrLen,
SQL_DRIVER_COMPLETE)
Last parameter allows driver to prompt for information if
connStr doesn’t contain all necessary information.
ODBC: Connection
• Specify a Driver or DSN
• Driver: Must specify all options in connection string
• DSN: Can specify options in connection string
Example:
“DSN=Couchbase;UID=kylep;PWD=testPassword;”
ODBC: Connection String
• Allocate with SQLAllocHandle, created from SQLHSTMT
• Used for issuing queries, retrieving catalog metadata
• Free with SQLFreeHandle
ODBC: Statement
• Use SQLExecDirect for one-off queries
• Use SQLPrepare and SQLExecute for repeated queries
SQLExecDirect(hStmt, “<query>”, SQL_NTS)
or
SQLPrepare(hStmt, “<query>”, SQL_NTS)
SQLExecute(hStmt)
ODBC: Querying
• After execution, there is a cursor on the results, positioned
before the first row
• Use SQLFetch to move the cursor
• SQLGetData can be used to fetch cell by cell
• SQLBindCol can also be used, much more efficient
ODBC: Results
• Reuse connections so driver caches are effective
• Use SQLBindCol over SQLGetData
• Use array fetches with SQLBindCol
• Use SQLPrepare once, SQLExecute multiple times with parameters for
loading data
• Use parameter arrays when binding parameters with SQLBindParameter
• Bind types to match reported parameter or column types
ODBC: Performance Tips
SQLGetData vs. SQLBindCol
10 million rows, 3 columns of wide char, integer, decimal values
ODBC: Performance Tips
Method Time (s)
SQLGetData 141.428
SQLBindCol 6.102
SQLBindCol (array[100]) 2.747
• Is the Java version of ODBC
• Versions: 3.0, 4.0, 4.1, etc…
• JDBC version is tied to Java version
• Simba will supply JDBC 4.0 and 4.1 versions
• There is a driver manager, but role is very limited
• Errors are reported via exceptions, warnings via
getWarnings()
JDBC Technicals
• Relationship is again one-to-many
JDBC: Object Hierarchy
• Never used directly by your code
• Must be loaded by referencing using Class.forName()
• FQCNs
• com.simba.couchbase.jdbc4.Driver
• com.simba.couchbase.jdbc41.Driver
• URL
• “jdbc:couchbase://<host>:<port>/<schema>;UseN1QLMode=0/1”
JDBC: Driver
• Example
String url = “jdbc:couchbase://localhost:8093/default;”
Class.forName(“com.simba.couchbase.jdbc4.Driver”);
Connection con = DriverManager.getConnection(url);
• With JDBC 4.0 and later, Class.forName() can be omitted
JDBC: Driver
• Used directly by your code
• FQCNs
• com.simba.couchbase.jdbc4.DataSource
• com.simba.couchbase.jdbc41.DataSource
• Can be used to programmatically set connection properties by
using functions instead of a connection string
• Allows use of advanced features such as PooledConnection
• Used less often than Driver
JDBC: DataSource
• Can create child statement objects for queries
• Can create DatabaseMetaData objects for metadata via
getMetaData()
• Common pitfalls
• Not closing connections; use a finally block to ensure it is closed
• Not checking warnings, ever; call getWarnings() regularly
• Creating a new connection for every operation; reuse connections where
possible
JDBC: Connection
• DatabaseMetaData
• Created by Connection objects
• Actually only one object per connection, cached and reused
• Provides access to catalog metadata
• getCatalogs(), getTables(), getColumns(), etc…
• Provides access to database metadata
• getDatabaseProductVersion(), getIdentifierQuoteString(), etc…
JDBC: Database MetaData
• Created by Connection objects
• Three different types
• Statement – for one-off querying
• PreparedStatement – for queries with parameters
• CallableStatement – for stored procedures with output parameters*
• Statement objects will eventually dispose of themselves once
out of scope, but best practice is to close() them when done
JDBC: Statement Objects
• Cannot use parameters
• Use execute(), executeQuery(), or executeUpdate() to
execute SQL or N1QL queries
JDBC: Statement
execute() Example
Statement stmt = conn.createStatement();
try {
if (stmt.execute(“select * from beer-sample”)) {
ResultSet rs = stmt.getResultSet();
rs.close();
}
}
finally {
stmt.close();
}
JDBC: Statement
• For use with parameters
• Can get metadata about results before execution with
getResultSetMetaData()
• Can get metadata about parameters using
getParameterMetaData()
• Use set*() functions to provide parameter values
JDBC: PreparedStatement
• When loading data, use batches
• Set all required parameters for one execution
• Call addBatch() to add the current set of parameters
• Call executeBatch() to execute all added batches at once
• Set parameters as reported types to avoid conversion overhead
in the driver
• Reuse the statement for multiple executions
JDBC: PreparedStatement
• Represents query results or catalog metadata
• Describe the result set using getMetaData()
• Move through result using next()
• Can use isAfterLast(), isFirst(), isLast(), etc. to check cursor position.
• Retrieve cell values using get*() methods
• The driver supports all conversions between types listed by the JDBC spec
• Try to retrieve as requested type to avoid conversion overhead
• Remember to check wasNull() after calling get*() method
JDBC: ResultSet
ResultSet Example
ResultSet rs = stmt.executeQuery(“<query>”);
try {
int numColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
for (int i = 0; i < numColumns; ++i) {
System.out.println(rs.getString(i));
}
}
}
finally {
rs.close();
}
JDBC: ResultSet
Q & A
simba.com

More Related Content

What's hot (18)

PPT
Css
myrajendra
 
ODP
Introduction to SQL Alchemy - SyPy June 2013
Roger Barnes
 
PPTX
Jdbc
Yamuna Devi
 
PPTX
java Jdbc
Ankit Desai
 
PPTX
JDBC
Ashish K
 
PPTX
Java.sql package
myrajendra
 
PPT
Jdbc day-1
Soham Sengupta
 
PPTX
Latest Advance Animated Ado.Net With JDBC
Tarun Jain
 
PPTX
Interface callable statement
myrajendra
 
PDF
WebLogic on ODA - Oracle Open World 2013
Michel Schildmeijer
 
PDF
Database and Java Database Connectivity
Gary Yeh
 
PDF
SQLcl the next generation of SQLPlus?
Zohar Elkayam
 
PPTX
Is SQLcl the Next Generation of SQL*Plus?
Zohar Elkayam
 
PPTX
Jdbc_ravi_2016
Ravinder Singh Karki
 
PDF
Change RelationalDB to GraphDB with OrientDB
Apaichon Punopas
 
PDF
Jdbc connectivity in java
Muthukumaran Subramanian
 
PDF
JPA and Hibernate Performance Tips
Vlad Mihalcea
 
Introduction to SQL Alchemy - SyPy June 2013
Roger Barnes
 
java Jdbc
Ankit Desai
 
JDBC
Ashish K
 
Java.sql package
myrajendra
 
Jdbc day-1
Soham Sengupta
 
Latest Advance Animated Ado.Net With JDBC
Tarun Jain
 
Interface callable statement
myrajendra
 
WebLogic on ODA - Oracle Open World 2013
Michel Schildmeijer
 
Database and Java Database Connectivity
Gary Yeh
 
SQLcl the next generation of SQLPlus?
Zohar Elkayam
 
Is SQLcl the Next Generation of SQL*Plus?
Zohar Elkayam
 
Jdbc_ravi_2016
Ravinder Singh Karki
 
Change RelationalDB to GraphDB with OrientDB
Apaichon Punopas
 
Jdbc connectivity in java
Muthukumaran Subramanian
 
JPA and Hibernate Performance Tips
Vlad Mihalcea
 

Viewers also liked (9)

PDF
Guney afrika cum_ulke_raporu_2013
UlkeRaporlari2013
 
DOCX
Lamperd_SWOT
Phillip LiPari
 
PPTX
Презентатция на тему «распечатывааем презентацию» Nikiforov Vladimir
ecko_1972
 
PDF
CV Malcolm McCay 201607
Malcolm McCay
 
PDF
Interview by Reed (2014)
Muhammad Yusuf Osman
 
PPTX
diccionario pictórico
ysy15
 
PPTX
Foods to Eat & Avoid in Parkinson's in Hindi Iपार्किंसंस में क्या खाए और क्या...
Herbal Daily
 
PPTX
Foods to Eat in Constipation, Acidity & Gas
Herbal Daily
 
PDF
Almanya ulke raporu_2013
UlkeRaporlari2013
 
Guney afrika cum_ulke_raporu_2013
UlkeRaporlari2013
 
Lamperd_SWOT
Phillip LiPari
 
Презентатция на тему «распечатывааем презентацию» Nikiforov Vladimir
ecko_1972
 
CV Malcolm McCay 201607
Malcolm McCay
 
Interview by Reed (2014)
Muhammad Yusuf Osman
 
diccionario pictórico
ysy15
 
Foods to Eat & Avoid in Parkinson's in Hindi Iपार्किंसंस में क्या खाए और क्या...
Herbal Daily
 
Foods to Eat in Constipation, Acidity & Gas
Herbal Daily
 
Almanya ulke raporu_2013
UlkeRaporlari2013
 
Ad

Similar to BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC (20)

PPTX
Java- JDBC- Mazenet Solution
Mazenetsolution
 
PDF
Jdbc
mishaRani1
 
PPTX
Introduction to JDBC and ODBC.pptx jdjdnjdjdndjdjndj
mahindrakarakanksha
 
PPT
Basic Java Database Connectivity(JDBC)
suraj pandey
 
PPT
JDBC.ppt
ChagantiSahith
 
PPT
jdbc
Gayatri Patel
 
PPTX
Jdbc introduction
Rakesh Kumar Ray
 
PPT
Jdbc connectivity
arikazukito
 
PDF
Unit 5.pdf
saturo3011
 
PDF
JDBC Presentation with JAVA code Examples.pdf
ssuser8878c1
 
PPTX
Core jdbc basics
Sourabrata Mukherjee
 
PPTX
java database connectivity for java programming
rinky1234
 
PPTX
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
rohanbawadkar
 
PPTX
Jdbc
DeepikaT13
 
PPTX
JAVA DATABASE CONNECTIVITY(JDBC CONNECTIVITY).pptx
JGEETHAPRIYA
 
PPTX
Advance Java Programming (CM5I)5.Interacting with-database
Payal Dungarwal
 
PDF
Jdbc 1
Tuan Ngo
 
PPTX
Rajesh jdbc
Aditya Sharma
 
PPTX
Module 3_CSE3146-Advanced Java Programming-JDBC-PPTs.pptx
aruthras2323
 
Java- JDBC- Mazenet Solution
Mazenetsolution
 
Introduction to JDBC and ODBC.pptx jdjdnjdjdndjdjndj
mahindrakarakanksha
 
Basic Java Database Connectivity(JDBC)
suraj pandey
 
JDBC.ppt
ChagantiSahith
 
Jdbc introduction
Rakesh Kumar Ray
 
Jdbc connectivity
arikazukito
 
Unit 5.pdf
saturo3011
 
JDBC Presentation with JAVA code Examples.pdf
ssuser8878c1
 
Core jdbc basics
Sourabrata Mukherjee
 
java database connectivity for java programming
rinky1234
 
Jdjdbcbc Jdjdbcbc JdjdbcJdjdbcbc Jdjdbcbc Jdjdbcbcbc JdJdbcbc
rohanbawadkar
 
JAVA DATABASE CONNECTIVITY(JDBC CONNECTIVITY).pptx
JGEETHAPRIYA
 
Advance Java Programming (CM5I)5.Interacting with-database
Payal Dungarwal
 
Jdbc 1
Tuan Ngo
 
Rajesh jdbc
Aditya Sharma
 
Module 3_CSE3146-Advanced Java Programming-JDBC-PPTs.pptx
aruthras2323
 
Ad

Recently uploaded (20)

PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 

BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC

  • 1. Open Connectivity BI, Integration, and Apps on Couchbase using ODBC and JDBC June, 2015
  • 2. • Who I am • Driver(s) Overview • Relational Model • Demos • ODBC in-depth • JDBC in-depth • QA Contents
  • 3. • Worked in the data access space for eight years and counting • ODBC, OLEDB, JDBC, ADO.NET, ODBO, XMLA • Core developer for the current generation of Simba’s data access technologies • Collaborated at an Engineering Level with Simba ISV Customers to design and implement data drivers that are today being shipped world wide Kyle at a glance
  • 4. • Simba connects people to data. • HQ’ed in Vancouver, BC. • 100ish employees. • Founded in 1991. • In 1992, Simba co-authored the original ODBC standard with Microsoft. • Simba produces the SimbaEngine® SDK and drivers for the leading data sources on multiple platforms. Simba Technologies at a glance
  • 7. • Partnership to create read/write ODBC and JDBC drivers • ODBC 3.80 • JDBC 4.0 and 4.1 • Allow easy access to data within Couchbase from your favourite BI and ETL tools Why is Simba here?
  • 8. What is an ODBC / JDBC Driver? N1QL mode to allow easy and advanced analytics
  • 9. • Couchbase is NoSQL • Dynamic schema, documents vary within a bucket • ODBC and JDBC are SQL • Expect a fixed schema, each column is one type • Must map from dynamic schema data to fixed schema data Schema(less)
  • 10. • SQL • Catalog, Schema, Table • Couchbase • Namespace, Keyspace Schema => Namespace Table => Keyspace (sort of) Relational Mapping http://www.prabathsl.com/2013/02/document-oriented-database_14.html
  • 11. Sample JSON Document: {“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]} Simple Flattening Id Name Values[0] Values[1] 1 Couchbase V1 V2
  • 12. Sample JSON Document: {“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]} Parent Child Re-Normalization Id Name 1 Couchbase Id Index Value 1 0 V1 1 1 V2
  • 13. Demos
  • 14. • C API • Versions: 2.x, 3.0, 3.52, 3.80, etc… • Non-Windows platforms are ODBC 3.52 • Driver Managers • Windows, iODBC, unixODBC, etc… • All functions have return codes • SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, etc… ODBC Technicals
  • 15. • SQLHENV, SQLHDBC, SQLHSTMT, SQLHDESC • Relationship is one-to-many ODBC: Handles
  • 16. • Allocate with SQLAllocHandle, free with SQLFreeHandle • Ensure you set the version of ODBC in use SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3_80, SQL_IS_INTEGER) ODBC: Environment
  • 17. • Allocate with SQLAllocHandle, created from SQLHENV • Maintains the actual connection to Couchbase • Create child statement objects to do work • Disconnect with SQLDisconnect, free with SQLFreeHandle ODBC: Connection
  • 18. Open a connection using SQLDriverConnect SQLDriverConnect( hDbc, windowHandle, connStr, SQL_NTS, connStrLen &outStrLen, SQL_DRIVER_COMPLETE) Last parameter allows driver to prompt for information if connStr doesn’t contain all necessary information. ODBC: Connection
  • 19. • Specify a Driver or DSN • Driver: Must specify all options in connection string • DSN: Can specify options in connection string Example: “DSN=Couchbase;UID=kylep;PWD=testPassword;” ODBC: Connection String
  • 20. • Allocate with SQLAllocHandle, created from SQLHSTMT • Used for issuing queries, retrieving catalog metadata • Free with SQLFreeHandle ODBC: Statement
  • 21. • Use SQLExecDirect for one-off queries • Use SQLPrepare and SQLExecute for repeated queries SQLExecDirect(hStmt, “<query>”, SQL_NTS) or SQLPrepare(hStmt, “<query>”, SQL_NTS) SQLExecute(hStmt) ODBC: Querying
  • 22. • After execution, there is a cursor on the results, positioned before the first row • Use SQLFetch to move the cursor • SQLGetData can be used to fetch cell by cell • SQLBindCol can also be used, much more efficient ODBC: Results
  • 23. • Reuse connections so driver caches are effective • Use SQLBindCol over SQLGetData • Use array fetches with SQLBindCol • Use SQLPrepare once, SQLExecute multiple times with parameters for loading data • Use parameter arrays when binding parameters with SQLBindParameter • Bind types to match reported parameter or column types ODBC: Performance Tips
  • 24. SQLGetData vs. SQLBindCol 10 million rows, 3 columns of wide char, integer, decimal values ODBC: Performance Tips Method Time (s) SQLGetData 141.428 SQLBindCol 6.102 SQLBindCol (array[100]) 2.747
  • 25. • Is the Java version of ODBC • Versions: 3.0, 4.0, 4.1, etc… • JDBC version is tied to Java version • Simba will supply JDBC 4.0 and 4.1 versions • There is a driver manager, but role is very limited • Errors are reported via exceptions, warnings via getWarnings() JDBC Technicals
  • 26. • Relationship is again one-to-many JDBC: Object Hierarchy
  • 27. • Never used directly by your code • Must be loaded by referencing using Class.forName() • FQCNs • com.simba.couchbase.jdbc4.Driver • com.simba.couchbase.jdbc41.Driver • URL • “jdbc:couchbase://<host>:<port>/<schema>;UseN1QLMode=0/1” JDBC: Driver
  • 28. • Example String url = “jdbc:couchbase://localhost:8093/default;” Class.forName(“com.simba.couchbase.jdbc4.Driver”); Connection con = DriverManager.getConnection(url); • With JDBC 4.0 and later, Class.forName() can be omitted JDBC: Driver
  • 29. • Used directly by your code • FQCNs • com.simba.couchbase.jdbc4.DataSource • com.simba.couchbase.jdbc41.DataSource • Can be used to programmatically set connection properties by using functions instead of a connection string • Allows use of advanced features such as PooledConnection • Used less often than Driver JDBC: DataSource
  • 30. • Can create child statement objects for queries • Can create DatabaseMetaData objects for metadata via getMetaData() • Common pitfalls • Not closing connections; use a finally block to ensure it is closed • Not checking warnings, ever; call getWarnings() regularly • Creating a new connection for every operation; reuse connections where possible JDBC: Connection
  • 31. • DatabaseMetaData • Created by Connection objects • Actually only one object per connection, cached and reused • Provides access to catalog metadata • getCatalogs(), getTables(), getColumns(), etc… • Provides access to database metadata • getDatabaseProductVersion(), getIdentifierQuoteString(), etc… JDBC: Database MetaData
  • 32. • Created by Connection objects • Three different types • Statement – for one-off querying • PreparedStatement – for queries with parameters • CallableStatement – for stored procedures with output parameters* • Statement objects will eventually dispose of themselves once out of scope, but best practice is to close() them when done JDBC: Statement Objects
  • 33. • Cannot use parameters • Use execute(), executeQuery(), or executeUpdate() to execute SQL or N1QL queries JDBC: Statement
  • 34. execute() Example Statement stmt = conn.createStatement(); try { if (stmt.execute(“select * from beer-sample”)) { ResultSet rs = stmt.getResultSet(); rs.close(); } } finally { stmt.close(); } JDBC: Statement
  • 35. • For use with parameters • Can get metadata about results before execution with getResultSetMetaData() • Can get metadata about parameters using getParameterMetaData() • Use set*() functions to provide parameter values JDBC: PreparedStatement
  • 36. • When loading data, use batches • Set all required parameters for one execution • Call addBatch() to add the current set of parameters • Call executeBatch() to execute all added batches at once • Set parameters as reported types to avoid conversion overhead in the driver • Reuse the statement for multiple executions JDBC: PreparedStatement
  • 37. • Represents query results or catalog metadata • Describe the result set using getMetaData() • Move through result using next() • Can use isAfterLast(), isFirst(), isLast(), etc. to check cursor position. • Retrieve cell values using get*() methods • The driver supports all conversions between types listed by the JDBC spec • Try to retrieve as requested type to avoid conversion overhead • Remember to check wasNull() after calling get*() method JDBC: ResultSet
  • 38. ResultSet Example ResultSet rs = stmt.executeQuery(“<query>”); try { int numColumns = rs.getMetaData().getColumnCount(); while (rs.next()) { for (int i = 0; i < numColumns; ++i) { System.out.println(rs.getString(i)); } } } finally { rs.close(); } JDBC: ResultSet
  • 39. Q & A

Editor's Notes

  • #8: Note that Simba will provide and maintain the drivers, to obtain them you need to contact Simba.
  • #9: Talk about using REST to talk to Couchbase, sent N1QL queries straight to Couchbase. Showing ODBC diagram, JDBC is identical.
  • #14: ODBC: Excel/PowerBI JDBC: Lumira, potentially Pentaho