TechTip: Implementing JSON in DB2 Made Easy

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

DB2 JSON is simple to implement and maintain.


Editor's note: This article is an excerpt from the book DB2 10.1/10.5 for Linux, UNIX, and Windows Database Administration (Exams 611 and 311): Certification Study Guide.

 

IBM DB2 10.5 FP1 introduced JSON support. DB2 JSON provides a complete storage/persistence solution for JSON documents. The solution combines application server-side components with JSON enhancements and functions in the DB2 engine.

 

This configuration provides a NoSQL API that uses DB2 to store, retrieve, modify, parse, and index JSON documents in DB2. The application server-side component is Java-based. So a Java API is included that allows native Java applications to exercise all the JSON capabilities directly.

 

For applications written in other languages, the solution also provides the Wire Listener Gateway (WLG) between MongoDB applications and a DB2 database server. This allows Mongo applications that are written in a supported language (such as Java, Node.js, or PyMongo) or that use the Mongo CLI to communicate with a DB2 database with no code changes. (Java applications can use the Wire Listener but may find advantage in using the Java API methods directly.)

 

DB2 JSON is simple to implement and maintain. The interface is contained within the nosqljson.jar file.

 

The following requirements are necessary to implement JSON support:

 

  • DB2 10.5.0.1 or higher Java client
  • The jar files listed below (which are included) as well as startup scripts and documentation
  • DFT_TABLE_ORG = ROW
  • DB2 database at 10.5 FP1 or higher
  • Java in shell PATH ( Java 1.5 64-bit or higher)
  • CLASSPATH jar files:

»» db2jcc.jar (Java client)

»» nosqljson.jar (DB2 noSQL JSON)

»» wplistener.jar (Wire Protocol Listener)

»» js.jar (Rhino JavaScript engine—not required if only using Java methods directly)

 

Required for command shell:

  • Proper authority
  • CREATE TABLE and CREATE FUNCTION in schema SYSTOOLS or DBADM on the target database

 

Configuring the Database

The preferred database is one with automatic storage, code set UTF-8, and page size 32 KB. As the DB2 instance owner, configure the database for UNIX and Windows systems as follows.

 

On UNIX

Execute <DB2INSTALL PATH>/json/bin/db2nosql.sh.

If running a remote command, execute the following:

 

db2nosql.sh -user <USER> -hostName <HOSTNAME> -port <PORT> -db <DBNAME> -password <PASSWORD>

 

If running a local command, execute this instead:

 

db2nosql.sh -db <DBNAME>

 

On Windows

Execute <DB2INSTALL PATH>/json/bin/db2nosql.bat.

 

If running a remote command, execute the following:

 

db2nosql.bat -user <USER> -hostName <HOSTNAME> -port <PORT> -db <DBNAME> -password <PASSWORD>

 

If running a local command, execute this instead:

 

db2nosql.bat -db <DBNAME>

 

When prompted enter

 

enable(true)

 

The following is an example of the output:

 

db2nosql.sh

JSON Command Shell Setup and Launcher.

This batch script assumes your JRE is 1.5 and higher. 1.6 will mask your

password.

Type db2nosql.sh -help to see options

Enter DB:db3a_row

IBM DB2 NoSQL JSON API 1.1.0.0 build 1.3.44

Licensed Materials - Property of IBM

(c) Copyright IBM Corp. 2013 All Rights Reserved.

nosql>Type your JSON query and hit <ENTER>

nosql>Type help() or help for usage information. All commands are case

sensitive.

Meta-data tables and functions for NoSQL JSON have not been created or have

been created incorrectly.

Please run 'enable(true)' to create them.

You must have the correct admin privileges.

Run 'enable(false)' to see the SQL that will be used.

nosql>nosql>enable(true)

nosql>Executing SQL...

Database artifacts created successfully.

 

Managing JSON

You can control several of JSON’s features by using the nosql.properties file. Although you can place this file anywhere on the application server, you must include its location in the shell’s CLASSPATH (see the IBM Knowledge Center for details). Table lists the NoSQL properties.

 

NoSQL Properties

Property

Definition

nosql.asyncMaxThreadCount

Max number of asynchronous threads

nosql.connectionPoolSize

JDBC connection pool size

nosql.tracefile

Trace file name

nosql.tracelevel

Level of trace output

nosql.statementCacheSize

Internal statement cache size

nosql.afg.includeID

Aggregation query adds _id field if no custom_id is specified

nosql.caseSensitiveNames

Schema/collection as case-sensitive

nosql.multiTypedID

Enabled support for multiple _id fields to be different types for documents in

the same collection

 

 

Learn more with the book DB2 10.1/10.5 for Linux, UNIX, and Windows Database Administration (Exams 611 and 311): Certification Study Guide.

 

Mohankumar Saraswatipura

Mohankumar (Mohan) Saraswatipura works as a database solutions architect at Kronsys, Inc., focusing on IBM DB2, Linux, UNIX, and Windows solutions. Prior to his current position, he worked as a database solutions architect at Reckitt Benckiser Group, plc (UK), focusing on IBM Smart Analytics System 5600, Siebel, SQL Server, and SAP HANA solutions. 

Mohan is an IBM Champion (2010–2015) and a DB2’s Got Talent 2013 winner. He has written dozens of technical papers for IBM developerWorks and IBM Data magazine. He is an IBM-Certified DB2 Advanced Database Administrator, DB2 Application Developer, and DB2 Problem Determination Master. Mohan holds a Master’s of Technology (M Tech) degree in computer science and an Executive MBA (IT).


MC Press books written by Mohankumar Saraswatipura available now on the MC Press Bookstore.

DB2 10.1/10.5 for Linux, UNIX, and Windows Database Administration (Exams 611 and 311) DB2 10.1/10.5 for Linux, UNIX, and Windows Database Administration (Exams 611 and 311)
Master DB2 database administration and prepare for IBM's Exams 611 and 311: Certified Database Administrator.
List Price $134.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: