Monday, November 24, 2014

JDBC Basic Information

Driver URL format:

mainProtocol:subProtocol:dbName

- here mainProtocol should be always "jdbc"
- subProtocol may be varied depending on the database


JDBC Driver Names


DB Type Driver Name DB URL Format
MySQL com.mysql.jdbc.Driver jdbc:mysql://hostname/ databaseName
Sybase com.sybase.jdbc.SybDriver jdbc:sybase:Tds:hostname: port Number/databaseName
DB2 COM.ibm.db2.jdbc.net.DB2Driver
Oracle oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@hostname:port Number:databaseName


How to know the type of ResultSet?
Call getType() on ResultSet object.
It will return either of following integer values:


1. 1003    TYPE_FORWARD_ONLY
Can traverse in only forward direction
Not sensitive to the Database updates during the records traversal

2. 1004    TYPE_SCROLL_INSENSITIVE
Can traverse in both forward and reverse directions
Not sensitive to the Database updates during the records traversal

3. 1005    TYPE_SCROLL_SENSITIVE
Can traverse in both forward and reverse directions
Sensitive to the Database updates during the records traversal

Oracle driver(oracle.jdbc.driver.OracleDriver) does not support TYPE_SCROLL_SENSITIVE

How to know whether a ResultSet is read only or updatable?
Call getConcurrency() on ResultSet object, which will return either of the following two values:

1. 1007    CONCUR_READ_ONLY
ResultSet cannot be updatable

2. 1008    CONCUR_UPDATABLE
ResultSet is updatable

No comments:

Post a Comment