SQLJ

SQLJ was developed by The SQLJ Group, a consortium comprised of database vendors and Sun Microsystems. The SQLJ Group submitted SQLJ in three parts to the INCITS Technical Committee H2 on Database.  H2 has adopted the three parts into the SQL standard.

SQLJ, which stands for "SQL-Java¹," is a multi-part specification for using SQL with Java:

bulletPart 0: Embedded SQL in Java. This provides a somewhat more object-oriented approach to the standard way of embedding SQL statements in programs. Part 0 supports  static SQL statements in Java. It does not support dynamic SQL statements. Those are handled by JDBC. Part 0 does support mixing embedded static SQL statements with JDBC statements. Part 0 supports the same mapping between Java data types and SQL data types that is defined by JDBC. Also see the SQLJ execution environment (new window).
bulletPart 1: SQL routines using Java. This provides the ability to invoke methods written in Java from SQL code. The Java methods provide the implementation of SQL procedures. To support Part 1, a DBMS must have a Java Virtual Machine associated with it. Part 1 deals only with static methods. For an association between SQL functions and Java methods, each SQL parameter and its corresponding Java parameter must be able to be mapped and the two return types must be able to be mapped. Also see mapping SQL and Java data types (new window).
bulletPart 2: SQL types using Java. This defines SQL extensions for using Java classes as data types in SQL. Part 2 allows mapping of SQL:1999 User Defined Types (UDTs) to Java classes. It also allows importing a Java package into your SQL database by defining tables containing columns whose data type are specified to be a Java class. Structured types are associated with classes, attributes with fields, and initializers to constructors. All or part of an SQL type hierarchy can be represented in a Java class hierarchy. It is not necessary to associate the entire SQL type hierarchy to a Java hierarchy. Part 2 adds non-static methods to the static methods in Part1. Also see SQL:1999 (new window)

The mapping of Java to the attributes of SQL:1999 typed tables is more or less straightforward. There are, however, Java structures that do not map exactly to SQL structures. For example, a vector structure could be mapped to a fixed length ARRAY type, sets also could be mapped to a fixed length ARRAY type, and lists may be more problematic to map and may depend on how you are using them. You also have the option, instead of using typed tables, to store Java objects in a serialized byte stream as an SQL BLOB (Binary Large OBject). The BLOB representing the object would then be stored in a cell of a table. With the SQL BLOB approach, it is still possible to define methods that operate on the object. Either way, there will remain some impedance mismatch between Java and SQL:1999. See impedance mismatch (new window).

SQLJ uses the embedded database sublanguage approach when using the Java programming language. This is illustrated by the embedded SQL statements in this diagram.

Embedded database sublanguage

An example of a Part 0 embedded SQLJ statement that creates a new Person instance with a Social Security Number of "999999999" would be:

#sql {  INSERT 
        INTO person 
        VALUES ('999999999', 'Doug Barry');
     };

This code would then be processed by a SQLJ Part 0 Translator, which will look for these embedded statements and replace them with Java statements that cause the SQL statements to be executed. The code shown above would be in addition to any host programming code. If you also wanted to manipulate this new Person instance in the host program, you would need Java code in addition to this code fragment that populates the instance in Java along with the instance in the database.

Also see the NCITS H2 web site (new window).

For an architectural example of how JDBC can be used, see using SQLJ with application servers (new window).

¹ Using "SQLJ" avoids possible trademark problems with using the word "Java."

 

Web Services and Service-Oriented Architectures
Online articles>
Consulting
Mentoring
Speaking
Suggested programs
Stencils for the Savvy Manager's Guide
Links
Mail list
Privacy policy
Sitemap
Contact
Web Services articles
XML standards and vocabularies
Application server articles
Database concepts and standards>
Object database articles
Relational database articles
Object-relational mapping articles
XML database articles
XML middleware articles
Article Sponsorship
Reprint policy
Basic concepts for using a DBMS
Database models
DBMS standards>
Article suggestions
SQL-92
JDBC
SQLJ>
SQL:1999
ADO.NET
Java Data Objects (JDO)
ODMG 3.0
Detailed comparison of ODMG 3.0 and JDO
Summary comparison of DBMS standards
SQLJ execution environment
Mapping SQL and Java data types

Related books at Amazon.com


Java Programming with Oracle SQLJ
by Jason Price
Average Customer Review: 5 stars based on 10 reviews.
Customer Review: My knowledge of Oracle and Java is beginner/intermediate level and I like this book a lot. The book explains how SQLJ relates to SQL, PL/SQL, Java, JDBC and it provides a good introduction to the JDeveloper IDE (Integrated Development Environment). The book is written very clearly and the appearance and organization of the text is w...

Professional Java Server Programming J2EE Edition
by Subrahmanyam Allamaraju, Andrew Longshaw, Daniel O'Connor, Gordon Van Huizen, Jason Diamond, John Griffin, Mac Holden, Marcus Daley, Mark Wilcox, Richard Browett
Average Customer Review: 4 stars based on 30 reviews.
Customer Review: This book is one the most comprehensive ones that I've bought. It provides you with most of the possible technologies that you could use in a basic J2EE application. I love the section on the J2EE architecture. For newbies I typcially request that they read that section first. It does justice to basic topics like JDBC & Servlets & t...

Professional Oracle 8i Application Programming with Java, PL/SQL and XML
by Michael Awai, Matthew Bortniker, John Carnell, Kelly Cox, Daniel O'Connor, Mario Zucca, Sean Dillon, Thomas Kyte, Ann Horton, Frank Hubeny, Glenn E. Mitchell II, Kevin Mukhar, Gary Nicol, Guy Ruth Hammond
Average Customer Review: 4 stars based on 10 reviews.
Customer Review: To produce this book, Wrox took twenty expert Oracle developers and had each of them write about their area of expertise. The result is that whether you are a manager, a developer, or a DBA, if you are working with Oracle 8i this book should be on your desk. This book covers virtually every topic that you need to understand about th...

Understanding SQL and Java Together : A Guide to SQLJ, JDBC, and Related Technologies (The Morgan Kaufmann Series in Data Management Systems)
by Jim Melton, Andrew Eisenberg
Average Customer Review: 3 stars based on 4 reviews.
Customer Review: In the pletoria of books on Java and databases, this is the one book that just must be read. It gives a thourough enough introduction to JDBC 1.0 and 2.0 and SQLJ Parts 0-2. Very readable! Covers the subjects to just the right level for developers and database experts.

Professional Java Data: RDBMS, JDBC, SQLJ, OODBMS, JNDI, LDAP, Servlets, JSP, WAP, XML, EJBs, CMP2.0, JDO, Transactions, Performance, Scalability, Object and Data Modeling
by Thomas Bishop, Glenn E. Mitchell, John Bell, Bjarki Holm, Danny Ayers, Carl Calvert Bettis, Sean Rhody, Tony Loton, Michael Bogovich, Mark Wilcox, Lin Kelly Poon, Nitin Nanda, Rick Grehan, Matthew Ferris, Kelly Lin Poon
Average Customer Review: 4 stars based on 2 reviews.
Customer Review: For the past 2 years Wrox has been publishing books dedicated to Windows-based data access (ADO etc.), but the same cannot be said about their Java/database collection. Although you find chapters on JDBC scattered all-over almost all server-side Java related books by Wrox, there was no single volume from them that teaches JDBC first,...

More related books: Search Amazon.com for SQLJ

 

Copyright © 2000-2008 Barry & Associates, Inc. All Rights Reserved.
You can use this material for your work or classes. Click here for our reprint policy.
www.service-architecture.com

 

 Information on becoming a sponsor

 

 

Google

 

Barry & Associates, Inc.