docs-en

GridDB JDBC Driver Manual

table of contents


Introduction

GridDB JDBC (Java interface) is an application interface that conforms to conforms to SQL92 standard specification.

This document describes the handling method and notes of the JDBC driver of GridDB Community Edition (hereinafter referred to as GridDB CE).


Overview

This chapter consists of a description of the specified format and data types that can be used in a program using JDBC parameters, and the points to note during use.

Connection method

Driver specification

Add the JDBC driver file /usr/share/java/gridstore-jdbc.jar to the class path. When added, the driver will be registered automatically. In addition, import the driver class as follows if necessary (Normally not required).

Class.forName("com.toshiba.mwcloud.gs.sql.Driver");

To secure communication between the GridDB cluster and the client, using the SSL function, additionally specify /usr/share/java/gridstore-advanced.jar in the class path.

Connection URL format

The URL has the following forms (A) to (D). If the multicast method is used to compose a cluster, normally it is connected using method (A). The load will be automatically distributed on the GridDB cluster side and the appropriate nodes will be connected. Connect using other method only if multicast communication with the GridDB cluster is not possible.

(A) If connecting automatically to a suitable node in a GridDB cluster using the multicast method

jdbc:gs://(multicastAddress):(portNo)/(clusterName)/(databaseName)

(B) If connecting directly to a node in a GridDB cluster using the multicast method

jdbc:gs://(nodeAddress):(portNo)/(clusterName)/(databaseName)

(C) If connecting to a GridDB cluster using the fixed list method

If the fixed list method is used to compose a cluster, use this method to connect.

jdbc:gs:///(clusterName)/(databaseName)?notificationMember=(notificationMember)

* notificationMember can be changed by editing the gs_cluster.json file. The port in the address list can be changed by editing the gs_node.json file.

(D) If connecting to a GridDB cluster using the provider method [EE only]

If the provider method is used to compose a cluster, use this method to connect.

jdbc:gs:///(clusterName)/(databaseName)?notificationProvider=(notificationProvider)

* notificationProvider can be changed by editing the gs_cluster.json file.

If the user name and password are going to be included in the URL in either one of the cases (A) to (D), add them at the end of the URL as shown below.

?user=(user name)&password=(password)

Connection timeout settings

The connection timeout can be set in either of the following methods (A) or (B). Setting (B) is prioritized if both (A) and (B) are set. Default value of 300 seconds (5 minutes) is used if neither (1) or (2) has been set, or if there are no settings.

(A) Specify with the DriverManager#setLoginTimeout (int seconds)

The connection timeout is set in one of the following ways depending on the value of seconds. After setting, the connection timeout will be set in the connections to all the GridDB acquired by the DriverManager#getConnection or Driver#connect.

(B) Specify with DriverManager#getConnection(String url, Properties info) or Driver#connect(String url, Properties info)

Add a property to argument info in the key “loginTimeout”. If the value corresponding to the key “loginTimeout” could be converted to a numerical value, the connection timeout will be set in the connection obtained as follows.

Settings of other information

Along with the settings described above, the following information can be set at the time of connection.

The information above can be set in either of the following methods (A) or (B). An error occurs when the name is specified using both methods.

(A) Specify in URL

For authentication with the GridDB cluster, use internal authentication (INTERNAL) or LDAP authentication (LDAP) according to the cluster settings. To specify the authentication method during connection, add the following to the URL:

?authentication=(INTERNAL|LDAP)

Secure communication with the GridDB cluster through SSL. Three options are available: PREFERRED (follows the cluster settings), VERIFY (SSL is valid and performs server certificate validation), and DISABLED (SSL is invalid), add the following to the URL:

?sslMode=(PREFERRED|VERIFY|DISABLED)

*When LDAP authentication is used, disabling SSL communication is not recommended.

* To specify VERIFY for the settings for SSL communications (sslMode), settings on the GridDB cluster side are also required. For detail, see the section on “Communication encryption” in the GridDB Features Reference. If a certificate by the Certificate Authority (CA) is not in a truststore, import it using the keytool command. If necessary, specify a truststore (-Djavax.net.ssl.trustStore) and a password (-Djavax.net.ssl.trustStorePassword) as arguments upon launching java. Note that the driver does not support the checking of the expiration date of a CA certificate to ensure it is valid.

To establish a connection using an external communication path, add the following to the URL. This specification is enabled only when the value is set to “PUBLIC”.

?connectionRoute=PUBLIC

Note that establishing a connection using an external communication path also requires settings on the GridDB cluster. For details, see the section on a “client communication path” in the GridDB Features Reference.

To configure the cluster network in multicast mode when multiple network interfaces are available, the address of the interface to receive the multicast packets from can be specified. Add the following to the URL:

?notificationNetworkInferfaceAddress=(address of the interface to receive  the multicast packets from)

To include the application name in the URL, add it to the end of the URL as follows:

?applicationName=(application name)

To include the time zone in the URL, add it to the end of the URL as follows:

?timeZone=(time zone)

To also include the user name and the password in the URL, use the following method.

?user=(user name)&password=(password)&applicationName=(application name)&timeZone=(time zone)

Encode the time zone symbol “:” and other characters that need to be encoded in the URL format.

(B) Specify with DriverManager#getConnection(String url, Properties info) or Driver#connect(String url, Properties info)

Add the property with the following key to the argument info.

Points to note

Specifications

The specifications of the GridDB JDBC driver are shown in this chapter. The chapter explains mainly the support range of the driver as well as the differences with the JDBC standard. See the JDK API reference for the API specifications that conform to the JDBC standard unless otherwise stated. Please note that the following could be revised in the future versions.

Common items

Supported JDBC version

The following functions corresponding to some of the functions of JDBC4.1 are not supported.

Error processing

Use of unsupported functions

Invoke a method against a closed object

As per the JDBC specifications, when a method other than isClosed() is invoked for an object that has a close() method, e.g,. a connection object, etc., a SQLException will occur. The error name is JDBC_ALREADY_CLOSED.

Invalid null argument

If null is specified as the API method argument despite not being permitted, SQLException due to a JDBC_EMPTY_PARAMETER error will occur. Null is not permitted except for arguments which explicitly accepts null in the JDBC specifications or this guide.

If there are multiple error causes

If there are multiple error causes, control will be returned to the application at the point either one of the errors is detected. In particular, if use of an unsupported function is attempted, it will be detected earlier than other errors. For example, if there is an attempt to create a stored procedure for a closed connection object, an error indicating that the operation is “not supported” instead of “closed” will be returned.

Description of exception

A check exception thrown from the driver is made up of a SQLException or a subclass instance of the SQLException. Use the following method to get the exception details.

Error list

The list of main errors detected inside the driver is as follows.

Error no. Error code name Error description format
(See “GridDB error code”) JDBC_NOT_SUPPORTED Currently not supported
(See “GridDB error code”) JDBC_OPTIONAL_FEATURE_NOT_SUPPORTED Optional feature not supported
(See “GridDB error code”) JDBC_EMPTY_PARAMETER The parameter (argument name) must not be null
(See “GridDB error code”) JDBC_ALREADY_CLOSED Already closed
(See “GridDB error code”) JDBC_COLUMN_INDEX_OUT_OF_RANGE Column index out of range
(See “GridDB error code”) JDBC_VALUE_TYPE_CONVERSION_FAILED Failed to convert value type
(See “GridDB error code”) JDBC_UNWRAPPING_NOT_SUPPORTED Unwrapping interface not supported
(See “GridDB error code”) JDBC_ILLEGAL_PARAMETER Illegal value: (argument name)
(See “GridDB error code”) JDBC_UNSUPPORTED_PARAMETER_VALUE Unsupported (parameter name)
(See “GridDB error code”) JDBC_ILLEGAL_STATE Protocol error occurred
(See “GridDB error code”) JDBC_INVALID_CURSOR_POSITION Invalid cursor position
(See “GridDB error code”) JDBC_STATEMENT_CATEGORY_UNMATCHED Writable query specified for read only request Read only query specified for writable request
(See “GridDB error code”) JDBC_MESSAGE_CORRUPTED Protocol error

When there is an error in the source generating the error and so on, additional details may be added to the end of the error description mentioned above.

API detailed specifications

Connection interface

Describes each method of the connection interface. Unless otherwise stated, only the description for the case when connection has not been closed is included.

Transaction control

As for transaction control, which operates in automatic commitment mode, commit/rollback is not supported. Note that a request for a commitment or a rollback from applications which use transactions is ignored so that the transaction control may be available even for these applications. SQLFeatureNotSupportedException does not occur.

Transaction isolation level supports only TRANSACTION_READ_COMMITTED. Other levels cannot be set.

Methods that have differences with the JDBC specification

Method Description Difference with JDBC specification
void commit() Commit Ignore a commit request because the API has only an automatic commitment mode.
void rollback() Rollback Ignore a rollback request because the API has only an automatic commitment mode.
void setAutoCommit(boolean autoCommit) Set a commitment mode. Mode setting is unavailable because the API has only an automatic commitment mode. Setting autoCommit is ignored and true is always set.

Partially unsupported method

Method Description Unsupported feature
Statement createStatement(int resultSetType, int resultSetConcurrency) Create a statement. resultSetType supports ResultSet.TYPE_FORWARD_ONLY only, and resultSetConcurrency supports ResultSet.CONCUR_READ_ONLY only. For other values, SQLFeatureNotSupportedException will occur.
Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) Create a statement. resultSetType supports ResultSet.TYPE_FORWARD_ONLY only, resultSetConcurrency supports ResultSet.CONCUR_READ_ONLY only, and resultSetHoldability supports ResultSet.CLOSE_CURSORS_AT_COMMIT only. For other values, SQLFeatureNotSupportedException will occur.
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Create a prepared statement. resultSetType supports ResultSet.TYPE_FORWARD_ONLY only, and resultSetConcurrency supports ResultSet.CONCUR_READ_ONLY only. For other values, SQLFeatureNotSupportedException will occur.
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Create a prepared statement. resultSetType supports ResultSet.TYPE_FORWARD_ONLY only, resultSetConcurrency supports ResultSet.CONCUR_READ_ONLY only, and resultSetHoldability supports ResultSet.CLOSE_CURSORS_AT_COMMIT only. For other values, SQLFeatureNotSupportedException will occur.
void setTransactionIsolation(int level) Set a transaction isolation level. Argument “level” accepts only Connection.TRANSACTION_READ_COMMITTED. If any other value is set, SQLException will occur.

Supported method

Method Description
void close() Close connection.
Statement createStatement() Create a statement.
boolean getAutoCommit() Get commitment mode.
DatabaseMetaData getMetaData() Get DatabaseMetaData.
int getTransactionIsolation() Get the transaction isolation level.
boolean isClosed() Get whether the Connection is closed.
PreparedStatement prepareStatement(String sql) Create a prepared statement.

Setting and getting attributes

This section describes methods for setting and getting attributes other than transaction control methods.

Methods that have differences with the JDBC specification

Method Description Difference with JDBC specification
void setReadOnly(boolean readOnly) Sets the read-only mode of the Connection object. Ignore readOnly and always set false.

Partially unsupported method

Method Description Unsupported feature
void setHoldability(int holdability) Set the holding function of ResultSet object. Argument “holdability” accepts only ResultSet.CLOSE_CURSORS_AT_COMMIT. For other values, SQLFeatureNotSupportedException will occur.

Supported method

Method Description
int getHoldability() Get the holding function of the ResultSet object.
boolean isReadOnly() Get whether the Connection object is in read-only mode.
boolean isValid(int timeout) Get the state of connection.

Unsupported function

Unsupported methods in the connection interface are listed below. When these methods are executed, SQLFeatureNotSupportedException will occur.

DatabaseMetaData interface

This section describes DatabaseMetaData interface, which gets the metadata of a table.

Attribute that returns ResultSet

Among the methods that return ResultSet as the execution result in DatabaseMetaData interface, the supported methods are as follows. The methods that return ResultSets other than these are not supported.

Method Description
ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) Return the column information of a table.
ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) Return the index information of a table.
ResultSet getPrimaryKeys(String catalog, String schema, String table) Return the row key information of a table.
ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) Return the list of tables.
ResultSet getTableTypes() Return the type of a table.
ResultSet getTypeInfo() Return the list of column data types.

Each of the above methods is explained below.

DatabaseMetaData.getColumns
ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
DatabaseMetaData.getIndexInfo
ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate)
DatabaseMetaData.getPrimaryKeys
ResultSet getPrimaryKeys(String catalog, String schema, String table)
DatabaseMetaData.getTables
ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
DatabaseMetaData.getTableTypes
ResultSet getTableTypes()
DatabaseMetaData.getTypeInfo()
ResultSet getTypeInfo()

Method that returns a value

Among the methods of DatabaseMetaData interface, the execution results are listed about the method that returns simple value such as int type and String type as execution result.

Method Result  
allProceduresAreCallable() false  
allTablesAreSelectable() true  
autoCommitFailureClosesAllResultSets() false  
dataDefinitionCausesTransactionCommit() false  
dataDefinitionIgnoredInTransactions() true  
deletesAreDetected(type) false  
doesMaxRowSizeIncludeBlobs() false  
generatedKeyAlwaysReturned() false  
getCatalogSeparator() ”.”  
getCatalogTerm() “catalog”  
getDefaultTransactionIsolation() TRANSACTION_READ_COMMITTED  
getExtraNameCharacters() . - / = (unordered)  
getIdentifierQuoteString()  
getMaxBinaryLiteralLength() 0  
getMaxCatalogNameLength() 0  
getMaxCharLiteralLength() 0  
getMaxColumnNameLength() 0  
getMaxColumnsInGroupBy() 0  
getMaxColumnsInIndex() 0  
getMaxColumnsInOrderBy() 0  
getMaxColumnsInSelect() 0  
getMaxColumnsInTable() 0  
getMaxConnections() 0  
getMaxCursorNameLength() 0  
getMaxIndexLength() 0  
getMaxSchemaNameLength() 0  
getMaxProcedureNameLength() 0  
getMaxRowSize() 0  
getMaxStatementLength() 0  
getMaxStatements() 0  
getMaxTableNameLength() 0  
getMaxTablesInSelect() 0  
getMaxUserNameLength() 0  
getProcedureTerm() “procedure”  
getResultSetHoldability() CLOSE_CURSORS_AT_COMMIT  
getRowIdLifetime() true  
getSchemaTerm() “schema”  
getSearchStringEscape()  
getSQLKeywords() ””  
getSQLStateType() sqlStateSQL99  
getStringFunctions() ””  
getSystemFunctions() ””  
getURL() null  
getUserName() (user name)  
insertsAreDetected(type) false  
isCatalogAtStart() true  
isReadOnly() false  
locatorsUpdateCopy() false  
nullPlusNonNullIsNull() true  
nullsAreSortedAtEnd() false  
nullsAreSortedAtStart() false  
nullsAreSortedHigh() true  
nullsAreSortedLow() false  
othersDeletesAreVisible(type) false  
othersInsertsAreVisible(type) false  
othersUpdatesAreVisible(type) false  
ownDeletesAreVisible(type) false  
ownInsertsAreVisible(type) false  
ownUpdatesAreVisible(type) false  
storesLowerCaseIdentifiers() false  
storesLowerCaseQuotedIdentifiers() false  
storesMixedCaseIdentifiers() true  
storesMixedCaseQuotedIdentifiers() false  
storesUpperCaseIdentifiers() false  
storesUpperCaseQuotedIdentifiers() false  
supportsAlterTableWithAddColumn() false  
supportsAlterTableWithDropColumn() false  
supportsANSI92EntryLevelSQL() false  
supportsANSI92FullSQL() false  
supportsANSI92IntermediateSQL() false  
supportsBatchUpdates() false  
supportsCatalogsInDataManipulation() false  
supportsCatalogsInIndexDefinitions() false  
supportsCatalogsInPrivilegeDefinitions() false  
supportsCatalogsInProcedureCalls() false  
supportsCatalogsInTableDefinitions() false  
supportsColumnAliasing() true  
supportsConvert() false  
supportsConvert(fromType, toType) false  
supportsCoreSQLGrammar() true  
supportsCorrelatedSubqueries() true  
supportsDataDefinitionAndDataManipulationTransactions() false  
supportsDataManipulationTransactionsOnly() false  
supportsDifferentTableCorrelationNames() false  
supportsExpressionsInOrderBy() true  
supportsExtendedSQLGrammar() false  
supportsFullOuterJoins() false  
supportsGetGeneratedKeys() false  
supportsGroupBy() true  
supportsGroupByBeyondSelect() true  
supportsGroupByUnrelated() true  
supportsIntegrityEnhancementFacility() false  
supportsLikeEscapeClause() true  
supportsLimitedOuterJoins() true  
supportsMinimumSQLGrammar() true  
supportsMixedCaseIdentifiers() false  
supportsMixedCaseQuotedIdentifiers() true  
supportsMultipleOpenResults() false  
supportsMultipleResultSets() false  
supportsMultipleTransactions() false  
supportsNamedParameters() false  
supportsNonNullableColumns() true  
supportsOpenCursorsAcrossCommit() false  
supportsOpenCursorsAcrossRollback() false  
supportsOpenStatementsAcrossCommit() false  
supportsOpenStatementsAcrossRollback() false  
supportsOrderByUnrelated() true  
supportsOuterJoins() true  
supportsPositionedDelete() false  
supportsPositionedUpdate() false  
supportsResultSetConcurrency(type, concurrency) Only in the case where type is TYPE_FORWARD_ONLY, and concurrency is CONCUR_READ_ONLY  
supportsResultSetHoldability(holdability) Only in case of CLOSE_CURSORS_AT_COMMIT  
supportsResultSetType() Only in case of TYPE_FORWARD_ONLY  
supportsSavepoints() false  
supportsSchemasInDataManipulation() false  
supportsSchemasInIndexDefinitions() false  
supportsSchemasInPrivilegeDefinitions() false  
supportsSchemasInProcedureCalls() false  
supportsSchemasInTableDefinitions() false  
supportsSelectForUpdate() false  
supportsStatementPooling() false  
supportsStoredFunctionsUsingCallSyntax() false  
supportsStoredProcedures() false  
supportsSubqueriesInComparisons() false  
supportsSubqueriesInExists() true  
supportsSubqueriesInIns() true  
supportsSubqueriesInQuantifieds() false  
supportsTableCorrelationNames() false  
supportsTransactionIsolationLevel(level) Only in case of TRANSACTION_READ_COMMITTED  
supportsTransactions() true  
supportsUnion() true  
supportsUnionAll() true  
updatesAreDetected(type) false  
usesLocalFilePerTable() false  
usesLocalFiles() false  

Unsupported methods

Among the methods of DatabaseMetaData interface, the unsupported methods are listed below. When these methods are executed, SQLFeatureNotSupportedException will not occur and the following results will be returned.

Method Result
ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) Empty ResultSet
ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) Empty ResultSet
ResultSet getCatalogs() Empty ResultSet
ResultSet getClientInfoProperties() Empty ResultSet
ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) Empty ResultSet
ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) Empty ResultSet
ResultSet getExportedKeys(String catalog, String schema, String table) Empty ResultSet
ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) Empty ResultSet
ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) Empty ResultSet
ResultSet getImportedKeys(String catalog, String schema, String table) Empty ResultSet
ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) Empty ResultSet
ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) Empty ResultSet
ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) Empty ResultSet
ResultSet getSchemas() Empty ResultSet
ResultSet getSchemas(String catalog, String schemaPattern) Empty ResultSet
ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) Empty ResultSet
ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) Empty ResultSet
ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) Empty ResultSet
ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) Empty ResultSet
ResultSet getVersionColumns(String catalog, String schema, String table) Empty ResultSet

Statement interface

Set/get fetch size

Only check the specified value.

When checking this value, check that the number of rows obtained by getMaxRows() of the statement is not exceeded as well. Limits related to this value are stated only in the JDBC specifications from JDBC4.0 or earlier. However, unlike the previous JDBC specifications, this excludes the case in which the result of getMaxRows() has been set to the default value 0.

Set/get fetch direction

Only FETCH_FORWARD is supported for the fetch direction. A SQLException occurs if FETCH_FORWARD is not specified.

Unsupported function

PreparedStatement interface

Set/get parameter

The following methods are supported. A SQLException occurs when invoking the query execution API like executeQuery without setting all parameters.

SQL execution

The following methods are supported.

Unsupported function

ParameterMetaData interface

This section describes the ParameterMetaData interface which gets PreparedStatement metadata.

All methods in the JDBC specification are supported but the methods below will always return a fixed value regardless of the value of argument param.

Method Result
int getParameterType(int param) Types.OTHER
String getParameterTypeName(int param) “UNKNOWN”
int getPrecision(int param) 0
int getScale(int param) 0
boolean isSigned(int param) false

ResultSet interface

Set/get fetch size

Only the specified value is checked and configuration changes will not affect the actual fetch process. When checking the value, check that the number of rows obtained by getMaxRows() of the statement in the source generating the target ResultSet is not exceeded as well. This limit is stated only in the JDBC specifications from JDBC4.0 or earlier. However, unlike the previous JDBC specifications, this excludes the case in which the result of getMaxRows() has been set to the default value 0. Actual fetch process is not affected but the revised setting can be acquired.

Set/get fetch direction

Only FETCH_FORWARD is supported for the fetch direction. A SQLException occurs if FETCH_FORWARD is not specified. This behavior is different from the JDBC specifications.

Get cursor data

The following cursor-related methods are supported.

Since the only fetch direction supported is FETCH_FORWARD, when the following method is invoked, a SQLException caused by a command being invoked against a FETCH_FORWARD type ResultSet will occur.

Management of warnings

As warnings will not be recorded, the actions to manage warnings are therefore as follows.

Method Behavior
getWarnings() null
clearWarnings() Warnings are not cleared.

Attribute that returns fixed value

The support status of a method to return a fixed value all the time while the ResultSet remains open is as follows.

Method Result
getCursorName() null
getType() TYPE_FORWARD_ONLY
getConcurrency() CONCUR_READ_ONLY
getMetaData() (JDBC-compliant)
getStatement() (JDBC-compliant)

Data type conversion

When getting the value of a specified column, if the data type maintained by the ResultSet differs from the requested data type, data type conversion will be attempted for the following combinations only.

The Java type of the destination BOOL INTEGRAL *1 FLOATING *2 TIMESTAMP STRING BLOB
boolean ✔ *3     ✔ *4  
byte    
short    
int    
long    
float      
double      
byte[]    
java.sql.Date       ✔ *5  
Time       ✔ *5  
Timestamp       ○ ※8 ○ ※5  
String ✔ *6 ✔ *7
Blob         ✔ *7
Object

Get column value

Column values can be obtained using the method corresponding to supported type conversion destination types. As to how to specify columns, both column labels and column indexes are supported.

In obtaining column values, the following objects are obtained for TIMESTAMP columns according to their precision:

Besides these, the following functions can be used.

Error processing

Unsupported function

The following optional functions are not supported. All overloads for which the argument has been omitted are not supported.

ResultSetMetaData interface

This section describes the ResultSetMetaData interface which gets the search result ResultSet metadata.

For all the methods in the JDBC specification of the ResultSetMetaData interface, the contents and the execution results of each method are described under the following classification.

Data type of column

ResultSetMetaData interface has a method that returns the column data type of the search result ResultSet.

Method Description
String getColumnClassName(int column) Returns the class name of the specified column data type.
int getColumnType(int column) Return the value of the specified column data type.
String getColumnTypeName(int column) Return the name of the specified column data type.

The correspondence between the column data type and the value of the execution result of each method is shown below.

Data type of a column getColumnClassName getColumnType getColumnTypeName
BOOL “java.lang.Boolean” Types.BIT “BOOL”
STRING “java.lang.String” Types.VARCHAR “STRING”
BYTE “java.lang.Byte” Types.TINYINT “BYTE”
SHORT “java.lang.Short” Types.SMALLINT “SHORT”
INTEGER “java.lang.Integer” Types.INTEGER “INTEGER”
LONG “java.lang.Long” Types.BIGINT “LONG”
FLOAT “java.lang.Float” Types.FLOAT “FLOAT”
DOUBLE “java.lang.Double” Types.DOUBLE “DOUBLE”
TIMESTAMP “java.util.Date” Types.TIMESTAMP “TIMESTAMP”
TIMESTAMP (3) “java.util.Date” Types.TIMESTAMP “TIMESTAMP”
TIMESTAMP (6) “java.sql.Timestamp” Types.TIMESTAMP “TIMESTAMP”
TIMESTAMP (9) “java.sql.Timestamp” Types.TIMESTAMP “TIMESTAMP”
BLOB “java.sql.Blob” Types.BLOB “BLOB”
GEOMETRY “java.lang.Object” Types.OTHER “UNKNOWN”
ARRAY “java.lang.Object” Types.OTHER “UNKNOWN”
When the data type of a column cannot be identified (*1) “java.lang.Object” Types.OTHER “UNKNOWN”

[Memo]

Attribute that returns a value

The result of executing the method other than returning the data type of the column in the ResultSetMetaData interface is shown below.

Method Result
String getCatalogName(int column) ””
int getColumnCount() The number of columns
int getColumnDisplaySize(int column) 131072
String getColumnLabel(int column) The label name of a column
String getColumnName(int column) The name of a column
int getPrecision (int column) For TIMESTAMP, specify 9, which is the number of digits in the fractional seconds for nanosecond, as the maximum precision; for other types, specify 0.
int getScale(int column) 0
String getSchemaName(int column) ””
String getTableName(int column) ””
boolean isAutoIncrement(int column) false
boolean isCaseSensitive(int column) true
boolean isCurrency(int column) false
boolean isDefinitelyWritable(int column) true
int isNullable(int column) The constant ResultSetMetaData.columnNullable(=1) that allows NULL values for the column, or the constant columnNoNulls(=0) that does not allow NULL values for the column
boolean isReadOnly(int column) false
boolean isSearchable(int column) true
boolean isSigned(int column) false
boolean isWritable(int column) true

Unsupported function

There are no unsupported methods (methods that cause SQLFeatureNotSupportedException) in the ResultSetMetaData interface.

Sample

A JDBC sample programs is given below.

// Execute Sample 2 before running this program. 
package test;

import java.sql.*;

public class SampleJDBC {
	public static void main(String[] args) throws SQLException {
		if (args.length != 5) {
			System.err.println(
				"usage: java SampleJDBC (multicastAddress) (port) (clusterName) (user) (password)");
			System.exit(1);
		}

		// url format "jdbc:gs://(multicastAddress):(portNo)/(clusterName)"
		String url = "jdbc:gs://" + args[0] + ":" + args[1] + "/" + args[2];
		String user = args[3];
		String password = args[4];

		System.out.println("DB Connection Start");

		// Connection to a GridDB cluster
		Connection con = DriverManager.getConnection(url, user, password);
		try {
			System.out.println("Start");
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("SELECT * FROM point01");
			ResultSetMetaData md = rs.getMetaData();
			while (rs.next()) {
				for (int i = 0; i < md.getColumnCount(); i++) {
					System.out.print(rs.getString(i + 1) + "|");
				}
				System.out.println("");
			}
			rs.close();
			System.out.println("End");
			st.close();
		} finally {
			System.out.println("DB Connection Close");
			con.close();
		}
	}
}

Copyright (c) 2017 TOSHIBA Digital Solutions Corporation