### Home Classes Methods

### In Files

- lib/sequel/adapters/jdbc.rb
- lib/sequel/adapters/jdbc/mssql.rb
- lib/sequel/adapters/jdbc/db2.rb

### Parent

Sequel::Database

### Methods

- ::new
- #call_sproc
- #connect
- #disconnect_connection
- #disconnect_error?
- #execute
- #execute_ddl
- #execute_dui
- #execute_insert
- #execute_prepared_statement
- #get_connection_from_jndi
- #get_tables
- #get_uri_from_jndi
- #indexes
- #java_sql_date
- #java_sql_datetime
- #java_sql_timestamp
- #jdbc_indexes
- #jdbc_tables
- #jdbc_views
- #jndi?
- #last_insert_id
- #log_connection_execute
- #metadata
- #set_ps_arg
- #setup_connection
- #tables
- #uri
- #views

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- schema_modification.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::Adapter
- Sequel::AdapterNotFound
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::BindArgumentMethods
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::TYPE_TRANSLATOR
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::HookFailed
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::Firebird::Dataset
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::Informix::Dataset
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLServer::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::DatasetMethods::StoredProcedureMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- Sequel::ODBC::DB2
- Sequel::ODBC::DB2::DatabaseMethods
- Sequel::ODBC::DB2::Dataset
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationAutoreloading::ClassMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::Rollback
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ServerBlock
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::AdapterMethods
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::Postgres::Dataset
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- Dataset
- Dataset::ArgumentMapper
- Dataset::BindArgumentMethods
- Dataset::PreparedStatementMethods
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel::JDBC::Database

JDBC Databases offer a fairly uniform interface that does not change much based on the sub adapter.

### Attributes

database_type[R]

The type of database we are connecting to

driver[R]

The Java database driver we are using

convert_types[RW]

Whether to convert some Java types to ruby types when retrieving rows. True by default, can be set to false to roughly double performance when fetching rows.

### Public Class Methods

new(opts) click to toggle source

Call the DATABASE_SETUP proc directly after initialization, so the object always uses sub adapter specific code. Also, raise an error immediately if the connection doesn’t have a uri, since JDBC requires one.

         # File lib/sequel/adapters/jdbc.rb, line 152
    152:       def initialize(opts)
    153:         super
    154:         @convert_types = typecast_value_boolean(@opts.fetch(:convert_types, true))
    155:         raise(Error, "No connection string specified") unless uri
    156:
    157:         resolved_uri = jndi? ? get_uri_from_jndi : uri
    158:
    159:         if match = /\Ajdbc:([^:]+)/.match(resolved_uri) and prok = DATABASE_SETUP[match[1].to_sym]
    160:           @driver = prok.call(self)
    161:         end
    162:       end

### Public Instance Methods

call_sproc(name, opts = {}) click to toggle source

Execute the given stored procedure with the give name. If a block is given, the stored procedure should return rows.

         # File lib/sequel/adapters/jdbc.rb, line 166
    166:       def call_sproc(name, opts = {})
    167:         args = opts[:args] || []
    168:         sql = "{call #{name}(#{args.map{'?'}.join(',')})}"
    169:         synchronize(opts[:server]) do |conn|
    170:           cps = conn.prepareCall(sql)
    171:
    172:           i = 0
    173:           args.each{|arg| set_ps_arg(cps, arg, i+=1)}
    174:
    175:           begin
    176:             if block_given?
    177:               yield log_yield(sql){cps.executeQuery}
    178:             else
    179:               case opts[:type]
    180:               when :insert
    181:                 log_yield(sql){cps.executeUpdate}
    182:                 last_insert_id(conn, opts)
    183:               else
    184:                 log_yield(sql){cps.executeUpdate}
    185:               end
    186:             end
    187:           rescue NativeException, JavaSQL::SQLException => e
    188:             raise_error(e)
    189:           ensure
    190:             cps.close
    191:           end
    192:         end
    193:       end

connect(server) click to toggle source

Connect to the database using JavaSQL::DriverManager.getConnection.

         # File lib/sequel/adapters/jdbc.rb, line 196
    196:       def connect(server)
    197:         opts = server_opts(server)
    198:         conn = if jndi?
    199:           get_connection_from_jndi
    200:         else
    201:           args = [uri(opts)]
    202:           args.concat([opts[:user], opts[:password]]) if opts[:user] && opts[:password]
    203:           begin
    204:             JavaSQL::DriverManager.setLoginTimeout(opts[:login_timeout]) if opts[:login_timeout]
    205:             JavaSQL::DriverManager.getConnection(*args)
    206:           rescue => e
    207:             raise e unless driver
    208:             # If the DriverManager can't get the connection - use the connect
    209:             # method of the driver. (This happens under Tomcat for instance)
    210:             props = java.util.Properties.new
    211:             if opts && opts[:user] && opts[:password]
    212:               props.setProperty("user", opts[:user])
    213:               props.setProperty("password", opts[:password])
    214:             end
    215:             opts[:jdbc_properties].each{|k,v| props.setProperty(k.to_s, v)} if opts[:jdbc_properties]
    216:             begin
    217:               driver.new.connect(args[0], props)
    218:             rescue => e2
    219:               e.message << "\n#{e2.class.name}: #{e2.message}"
    220:               raise e
    221:             end
    222:           end
    223:         end
    224:         setup_connection(conn)
    225:       end

execute(sql, opts={}, &block) click to toggle source

Execute the given SQL. If a block is given, if should be a SELECT statement or something else that returns rows.

         # File lib/sequel/adapters/jdbc.rb, line 229
    229:       def execute(sql, opts={}, &block)
    230:         return call_sproc(sql, opts, &block) if opts[:sproc]
    231:         return execute_prepared_statement(sql, opts, &block) if [Symbol, Dataset].any?{|c| sql.is_a?(c)}
    232:         synchronize(opts[:server]) do |conn|
    233:           statement(conn) do |stmt|
    234:             if block
    235:               yield log_yield(sql){stmt.executeQuery(sql)}
    236:             else
    237:               case opts[:type]
    238:               when :ddl
    239:                 log_yield(sql){stmt.execute(sql)}
    240:               when :insert
    241:                 log_yield(sql) do
    242:                   if requires_return_generated_keys?
    243:                     stmt.executeUpdate(sql, JavaSQL::Statement.RETURN_GENERATED_KEYS)
    244:                   else
    245:                     stmt.executeUpdate(sql)
    246:                   end
    247:                 end
    248:                 last_insert_id(conn, opts.merge(:stmt=>stmt))
    249:               else
    250:                 log_yield(sql){stmt.executeUpdate(sql)}
    251:               end
    252:             end
    253:           end
    254:         end
    255:       end

Also aliased as: execute_dui
execute_ddl(sql, opts={}) click to toggle source

Execute the given DDL SQL, which should not return any values or rows.

         # File lib/sequel/adapters/jdbc.rb, line 260
    260:       def execute_ddl(sql, opts={})
    261:         execute(sql, {:type=>:ddl}.merge(opts))
    262:       end

execute_dui(sql, opts={}, &block) click to toggle source
Alias for: execute
execute_insert(sql, opts={}) click to toggle source

Execute the given INSERT SQL, returning the last inserted row id.

         # File lib/sequel/adapters/jdbc.rb, line 266
    266:       def execute_insert(sql, opts={})
    267:         execute(sql, {:type=>:insert}.merge(opts))
    268:       end

indexes(table, opts={}) click to toggle source

Use the JDBC metadata to get the index information for the table.

         # File lib/sequel/adapters/jdbc.rb, line 271
    271:       def indexes(table, opts={})
    272:         m = output_identifier_meth
    273:         im = input_identifier_meth
    274:         schema, table = schema_and_table(table)
    275:         schema ||= opts[:schema]
    276:         schema = im.call(schema) if schema
    277:         table = im.call(table)
    278:         indexes = {}
    279:         metadata(:getIndexInfo, nil, schema, table, false, true) do |r|
    280:           next unless name = r[:column_name]
    281:           next if respond_to?(:primary_key_index_re, true) and r[:index_name] =~ primary_key_index_re
    282:           i = indexes[m.call(r[:index_name])] ||= {:columns=>[], :unique=>[false, 0].include?(r[:non_unique])}
    283:           i[:columns] << m.call(name)
    284:         end
    285:         indexes
    286:       end

Also aliased as: jdbc_indexes
jdbc_indexes(table, opts={}) click to toggle source
Alias for: indexes
jdbc_tables(opts={}) click to toggle source
Alias for: tables
jdbc_views(opts={}) click to toggle source
Alias for: views
jndi?() click to toggle source

Whether or not JNDI is being used for this connection.

         # File lib/sequel/adapters/jdbc.rb, line 289
    289:       def jndi?
    290:         !!(uri =~ JNDI_URI_REGEXP)
    291:       end

tables(opts={}) click to toggle source

All tables in this database

         # File lib/sequel/adapters/jdbc.rb, line 294
    294:       def tables(opts={})
    295:         get_tables('TABLE', opts)
    296:       end

Also aliased as: jdbc_tables
uri(opts={}) click to toggle source

The uri for this connection. You can specify the uri using the :uri, :url, or :database options. You don’t need to worry about this if you use Sequel.connect with the JDBC connectrion strings.

         # File lib/sequel/adapters/jdbc.rb, line 302
    302:       def uri(opts={})
    303:         opts = @opts.merge(opts)
    304:         ur = opts[:uri] || opts[:url] || opts[:database]
    305:         ur =~ /^\Ajdbc:/ ? ur : "jdbc:#{ur}"
    306:       end

views(opts={}) click to toggle source

All views in this database

         # File lib/sequel/adapters/jdbc.rb, line 309
    309:       def views(opts={})
    310:         get_tables('VIEW', opts)
    311:       end

Also aliased as: jdbc_views

### Private Instance Methods

disconnect_connection(c) click to toggle source

Close given adapter connections

         # File lib/sequel/adapters/jdbc.rb, line 316
    316:       def disconnect_connection(c)
    317:         c.close
    318:       end

disconnect_error?(exception, opts) click to toggle source

Raise a disconnect error if the SQL state of the cause of the exception indicates so.

         # File lib/sequel/adapters/jdbc.rb, line 321
    321:       def disconnect_error?(exception, opts)
    322:         cause = exception.respond_to?(:cause) ? exception.cause : exception
    323:         super || (cause.respond_to?(:getSQLState) && cause.getSQLState =~ /^08/)
    324:       end

execute_prepared_statement(name, opts={}) click to toggle source

Execute the prepared statement. If the provided name is a dataset, use that as the prepared statement, otherwise use it as a key to look it up in the prepared_statements hash. If the connection we are using has already prepared an identical statement, use that statement instead of creating another. Otherwise, prepare a new statement for the connection, bind the variables, and execute it.

         # File lib/sequel/adapters/jdbc.rb, line 333
    333:       def execute_prepared_statement(name, opts={})
    334:         args = opts[:arguments]
    335:         if Dataset === name
    336:           ps = name
    337:           name = ps.prepared_statement_name
    338:         else
    339:           ps = prepared_statements[name]
    340:         end
    341:         sql = ps.prepared_sql
    342:         synchronize(opts[:server]) do |conn|
    343:           if name and cps = conn.prepared_statements[name] and cps[0] == sql
    344:             cps = cps[1]
    345:           else
    346:             log_yield("Closing #{name}"){cps[1].close} if cps
    347:             cps = log_yield("Preparing#{" #{name}:" if name} #{sql}"){conn.prepareStatement(sql)}
    348:             conn.prepared_statements[name] = [sql, cps] if name
    349:           end
    350:           i = 0
    351:           args.each{|arg| set_ps_arg(cps, arg, i+=1)}
    352:           msg = "Executing#{" #{name}" if name}"
    353:           begin
    354:             if block_given?
    355:               yield log_yield(msg, args){cps.executeQuery}
    356:             else
    357:               case opts[:type]
    358:               when :ddl
    359:                 log_yield(msg, args){cps.execute}
    360:               when :insert
    361:                 log_yield(msg, args){cps.executeUpdate}
    362:                 last_insert_id(conn, opts.merge(:prepared=>true))
    363:               else
    364:                 log_yield(msg, args){cps.executeUpdate}
    365:               end
    366:             end
    367:           rescue NativeException, JavaSQL::SQLException => e
    368:             raise_error(e)
    369:           ensure
    370:             cps.close unless name
    371:           end
    372:         end
    373:       end

get_connection_from_jndi() click to toggle source

Gets the connection from JNDI.

         # File lib/sequel/adapters/jdbc.rb, line 376
    376:       def get_connection_from_jndi
    377:         jndi_name = JNDI_URI_REGEXP.match(uri)[1]
    378:         JavaxNaming::InitialContext.new.lookup(jndi_name).connection
    379:       end

get_tables(type, opts) click to toggle source

Backbone of the tables and views support.

         # File lib/sequel/adapters/jdbc.rb, line 390
    390:       def get_tables(type, opts)
    391:         ts = []
    392:         m = output_identifier_meth
    393:         metadata(:getTables, nil, nil, nil, [type].to_java(:string)){|h| ts << m.call(h[:table_name])}
    394:         ts
    395:       end

get_uri_from_jndi() click to toggle source

Gets the JDBC connection uri from the JNDI resource.

         # File lib/sequel/adapters/jdbc.rb, line 382
    382:       def get_uri_from_jndi
    383:         conn = get_connection_from_jndi
    384:         conn.meta_data.url
    385:       ensure
    386:         conn.close if conn
    387:       end

java_sql_date(date) click to toggle source

Support Date objects used in bound variables

         # File lib/sequel/adapters/jdbc.rb, line 398
    398:       def java_sql_date(date)
    399:         java.sql.Date.new(Time.local(date.year, date.month, date.day).to_i * 1000)
    400:       end

java_sql_datetime(datetime) click to toggle source

Support DateTime objects used in bound variables

         # File lib/sequel/adapters/jdbc.rb, line 403
    403:       def java_sql_datetime(datetime)
    404:         ts = java.sql.Timestamp.new(Time.local(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec).to_i * 1000)
    405:         ts.setNanos((datetime.sec_fraction * (RUBY_VERSION >= '1.9.0' ?  1000000000 : 86400000000000)).to_i)
    406:         ts
    407:       end

java_sql_timestamp(time) click to toggle source

Support fractional seconds for Time objects used in bound variables

         # File lib/sequel/adapters/jdbc.rb, line 410
    410:       def java_sql_timestamp(time)
    411:         ts = java.sql.Timestamp.new(time.to_i * 1000)
    412:         ts.setNanos(RUBY_VERSION >= '1.9.0' ? time.nsec : time.usec * 1000)
    413:         ts
    414:       end

last_insert_id(conn, opts) click to toggle source

By default, there is no support for determining the last inserted id, so return nil. This method should be overridden in sub adapters.

         # File lib/sequel/adapters/jdbc.rb, line 425
    425:       def last_insert_id(conn, opts)
    426:         nil
    427:       end

log_connection_execute(conn, sql) click to toggle source

Log the given SQL and then execute it on the connection, used by the transaction code.

         # File lib/sequel/adapters/jdbc.rb, line 418
    418:       def log_connection_execute(conn, sql)
    419:         statement(conn){|s| log_yield(sql){s.execute(sql)}}
    420:       end

metadata(*args, &block) click to toggle source

Yield the metadata for this database

         # File lib/sequel/adapters/jdbc.rb, line 430
    430:       def metadata(*args, &block)
    431:         synchronize do |c|
    432:           result = c.getMetaData.send(*args)
    433:           begin
    434:             metadata_dataset.send(:process_result_set, result, &block)
    435:           ensure
    436:             result.close
    437:           end
    438:         end
    439:       end

set_ps_arg(cps, arg, i) click to toggle source

Java being java, you need to specify the type of each argument for the prepared statement, and bind it individually. This guesses which JDBC method to use, and hopefully JRuby will convert things properly for us.

         # File lib/sequel/adapters/jdbc.rb, line 445
    445:       def set_ps_arg(cps, arg, i)
    446:         case arg
    447:         when Integer
    448:           cps.setLong(i, arg)
    449:         when Sequel::SQL::Blob
    450:           cps.setBytes(i, arg.to_java_bytes)
    451:         when String
    452:           cps.setString(i, arg)
    453:         when Float
    454:           cps.setDouble(i, arg)
    455:         when TrueClass, FalseClass
    456:           cps.setBoolean(i, arg)
    457:         when NilClass
    458:           cps.setString(i, nil)
    459:         when DateTime
    460:           cps.setTimestamp(i, java_sql_datetime(arg))
    461:         when Date
    462:           cps.setDate(i, java_sql_date(arg))
    463:         when Time
    464:           cps.setTimestamp(i, java_sql_timestamp(arg))
    465:         when Java::JavaSql::Timestamp
    466:           cps.setTimestamp(i, arg)
    467:         when Java::JavaSql::Date
    468:           cps.setDate(i, arg)
    469:         else
    470:           cps.setObject(i, arg)
    471:         end
    472:       end

setup_connection(conn) click to toggle source

Add a prepared_statements accessor to the connection, and set it to an empty hash. This is used to store adapter specific prepared statements.

         # File lib/sequel/adapters/jdbc.rb, line 477
    477:       def setup_connection(conn)
    478:         class << conn
    479:           attr_accessor :prepared_statements
    480:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.