Saturday 25 August 2012

Features of JDBC API


Features of JDBC 1.0 API:

1). The JDBC 1.0 API was the first officially JDBC API launched consists of the following java classes and interfaces that you can open connections to particular databases.
2). This version includes a completely redesigned administration console with an enhanced graphical interface to manage and monitor distributed virtual databases.
 
-->

Features of JDBC 1.2 API:

1). New pass through schedulers for increased performance.
2). The DatabaseMetaData code has been refactored to provide more transparency with regard to the underlying database engine.
3). It supports Updatabale ResultSets.

Features of JDBC 2.0 API:


1). RowSet technology -- providing a convenient means of handling and passing data
2). Distributed transactions -- allowing a transaction to span diverse DBMS servers
3). The DataSource interface as a means of making a connection. The Java Naming and Directory InterfaceTM (JNDI) is used for registering a DataSource object with a naming service and also for retrieving it.
4). Pooled connections -- allowing connections to be used and reused
-->

Features of JDBC 2.1 API:


1). Miscellaneous features, including performance hints, the use of character streams, full precision for java.math.BigDecimal values, additional security, and support for time zones in date, time, and timestamp values.
2). Scrollable result sets--using new methods in the ResultSet interface that allow the cursor to be moved to a particular row or to a position relative to its current position
3). Custom mapping of user-defined types (UDTs)
4). Batch updates
5). New data types--interfaces mapping the SQL3 data types
6). Programmatic updates--using ResultSet updater methods
-->

Features of JDBC 3.0 API:


1). Addition of metadata for retrieving SQL type hierarchies
2). Pooled statements -- reuse of statements associated with a pooled connection
3). Addition of the java.sql.Types.DATALINK data type -- allows JDBC drivers access to objects stored outside a data source
4). Savepoints -- allow a transaction to be rolled back to a designated savepoint
5). Ability to programmatically update BLOB, CLOB, ARRAY, and REF values.
6). Properties defined for ConnectionPoolDataSource -- specify how connections are to be pooled
7). Ability to retrieve and update the SQL structured type instance that a Ref object references
8). Metadata for parameters of a PreparedStatement object
9). ResultSet holdability -- ability to specify whether cursors should be held open or closed at the end of a transaction
10). Ability to retrieve values from automatically generated columns
-->

Features of JDBC 4.0 API:


1). Connection management enhancements.
2). SQL XML support
3). SQL exception handling enhancements.
4). DataSet implementation of SQl using Annotations
5). Ability to programmatically update BLOB, CLOB, ARRAY, and REF values.
6). Properties defined for ConnectionPoolDataSource -- specify how connections are to be pooled
 

List of Exceptions in JDBC API

1) BatchUpdateException:-An exception thrown when an error occurs during a batch update operation.
2) DataTruncation:-An exception that reports a DataTruncation warning (on reads) or throws a DataTruncation exception (on writes) when JDBC unexpectedly truncates a data value.
3) SQLException:-An exception that provides information on a database access error or other errors.
4) SQLWarning:-An exception that provides information on database access warnings.

JDBC API

The JDBCTM API provides universal data access from the JavaTM programming language. Using the JDBC 3.0 API, you can access virtually any data source, from relational databases to spreadsheets and flat files. JDBC technology also provides a common base on which tools and alternate interfaces can be built.
The JDBC API is part of the Java platform, which includes the Java™ Standard Edition (Java™ SE ) and the Java™ Enterprise Edition (Java™ EE). The JDBC 4.0 API is divided into two packages:

1). java.sql package

2). the javax.sql package, which adds server-side capabilities
 
 

JDBC Technology Drivers


To use the JDBC API with a particular database management system, you need a JDBC technology-based driver to mediate between JDBC technology and the database. Depending on various factors, a driver might be written purely in the Java programming language or in a mixture of the Java programming language and JavaTM Native Interface (JNI) native methods.
The latest SDK includes a JDBC-ODBC Bridge driver that makes most Open Database Connectivity (ODBC) drivers available to programmers using the JDBC API. JDBC-ODBC Bridge Driver describes the current status of this software. Note that the bridge driver included in the SDK is appropriate only for experimental use or when no other driver is available.

 

Package java.sql contains following Interfaces and classes.

List of Interfaces Summary:

1) Array:-The mapping in the Java programming language for the SQL type ARRAY.
2) Blob:-The representation (mapping) in the JavaTM programming language of an SQL BLOB value.
3) CallableStatement:-The interface used to execute SQL stored procedures.
4) Clob:-The mapping in the JavaTM programming language for the SQL CLOB type.
5) Connection:-A connection (session) with a specific database.
6) DatabaseMetaData:-Comprehensive information about the database as a whole.
7) Driver:-The interface that every driver class must implement.
8) ParameterMetaData:-An object that can be used to get information about the types and properties of the parameters in a PreparedStatement object.
9) PreparedStatement:-An object that represents a precompiled SQL statement.
10) Ref:-The mapping in the Java programming language of an SQL REF value, which is a reference to an SQL structured type value in the database.
11) ResultSet:-A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
12) ResultSetMetaData:-An object that can be used to get information about the types and properties of the columns in a ResultSet object.
13) Connection:-A connection (session) with a specific database.
14) Savepoint:-The representation of a savepoint, which is a point within the current transaction that can be referenced from the Connection.rollback method.
15) SQLData:-The interface used for the custom mapping of an SQL user-defined type (UDT) to a class in the Java programming language.
16) SQLInput:-An input stream that contains a stream of values representing an instance of an SQL structured type or an SQL distinct type.
17) SQLOutput:-The output stream for writing the attributes of a user-defined type back to the database.
18) Statement:-The object used for executing a static SQL statement and returning the results it produces.
19) Struct:-The standard mapping in the Java programming language for an SQL structured type.

List of Classes Summary:

1) Date:-A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value.
2) DriverPropertyInfo:-Driver properties for making a connection.
3) SQLPermission:-The permission for which the SecurityManager will check when code that is running in an applet calls the DriverManager.setLogWriter method or the DriverManager.setLogStream (deprecated) method.
4) Time:-A thin wrapper around the java.util.Date class that allows the JDBC API to identify this as an SQL TIME value.
5) Timestamp:-A thin wrapper around java.util.Date that allows the JDBC API to identify this as an SQL TIMESTAMP value.
6) Types:-The class that defines the constants that are used to identify generic SQL types, called JDBC types.

Friday 24 August 2012

Type 4 Driver


Type 4: Native-protocol driver (Pure)


In a Type 4 driver, a pure Java-based driver that communicates directly with vendor's database through socket connection.This kind of driver is extremely flexible, you don't need to install special software on the client or server. Further, these drivers can be downloaded dynamically.
Type 4 drivers are thus platform independent. They install inside the Java Virtual Machine of the client. This provides better performance than the type 1 and type 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls. Unlike the type 3 drivers, it does not need associated software to work.
 

Advantages:

1). The major benefit of using a type 4 jdbc drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web.
2). These drivers don't translate the requests into an intermediary format (such as ODBC).Performance is typically quite good.
3). The client application connects directly to the database server. No translation or middleware layers are used, improving performance.
4). You don’t need to install special software on the client or server. Further, these drivers can be downloaded dynamically.
 

Disadvantages:

1). Drivers are database dependent, as different database vendors use wildly different (and usually proprietary) network protocols.
2). It requires another server application to install and maintain. Traversing the recordset may take longer, since the data comes through the backend server.
 

Which is suitable driver for use?

1). The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only.
2). If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.
1). If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.
2). Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.

Type 3 Driver


Type 3 Driver - Network-Protocol Driver


Type 3 drivers are pure Java drivers that use a proprietary network protocol to communicate with JDBC middleware on the server. The middleware then translates the network protocol to database-specific function calls. Type 3 drivers are the most flexible JDBC solution because they do not require native database libraries on the client and can connect to many different databases on the back end. Type 3 drivers can be deployed over the Internet without client installation.
In a Type 3 driver, a three-tier approach is used to accessing databases. The JDBC clients use standard network sockets to communicate with an middleware application server. The socket information is then translated by the middleware application server into the call format required by the DBMS, and forwarded to the database server.This kind of driver is extremely flexible, since it requires no code installed on the client and a single driver can actually provide access to multiple databases.

 

Advantages:

1). Since the communication between client and the middleware server is database independent, there is no need for the database vendor library on the client. The client need not be changed for a new database.
2). This driver is server-based, so there is no need for any vendor database library to be present on client machines.
3). The middleware server (which can be a full fledged J2EE Application server) can provide typical middleware services like caching (of connections, query results, etc.), load balancing, logging, and auditing.
4). This driver is fully written in Java and hence Portable. It is suitable for the web.
5). There are many opportunities to optimize portability, performance, and scalability.
6). The net protocol can be designed to make the client JDBC driver very small and fast to load.
7). A single driver can handle any database, provided the middleware supports it.
8). This driver is very flexible allows access to multiple databases using one driver.
9). They are the most efficient amongst all driver types.
 

Disadvantages:

1). Requires database-specific coding to be done in the middle tier.
2). It requires another server application to install and maintain. Traversing the recordset may take longer, since the data comes through the backend server.
 

Type 2 Driver


Type 2: JDBC-Native API/partly Java driver:


The JDBC type 2 driver, also known as the Native-API driver, is a database driver implementation that uses the client-side libraries of the database.
In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls which are unique to the database. These drivers typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge, the vendor-specific driver must be installed on each client machine.
If we change the Database we have to change the native API as it is specific to a database and they are mostly obsolete now but you may realize some speed increase with a Type 2 driver, because it eliminates ODBC's overhead. Type 2 drivers are usually faster than Type 1 drivers. Like Type 1 drivers, Type 2 drivers require native database client libraries to be installed and configured on the client machine.

Advantages:

1). As there is no implementation of jdbc-odbc bridge, its considerably faster than a type 1 driver.
2). The distinctive characteristic of type 2 jdbc drivers are that they are typically offer better performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than that of Type1 and also it uses Native api which is Database specific.

Disadvantages:


1). The vendor client library needs to be installed on the client machine.
2). Type 2 drivers cannot be used for the Internet.
3). If we change the Database we have to change the native api as it is specific to a database
4). This driver is platform dependent
5). Usually not thread safe.
6). This driver supports all java applications except Applets
7). Like Type 1 drivers, it’s not written in Java Language which forms a portability issue.
 

JDBC Driver Types


What is JDBC Driver?


JDBC is a software component enabling a java application to interact with a database.For connecting with databases, JDBC requires drivers for each database. The JDBC driver established the connection to the database and implements the protocols for transferring the queries and result between client and database.
The Java.sql package that ships with JDK contains various classes with their behaviours defined and their actual implementaions are done in third-party drivers. Third party vendors implements the java.sql.Driver interface in their database driver.

Types of JDBC Drivers:

JDBC driver implementations vary because of the wide variety of operating systems and hardware platforms in which Java operates. Sun has divided the implementation types into four categories, Types 1, 2, 3, and 4.
 

4 types of jdbc drivers are elaborated in detail as shown below:

>Type 1: JDBC-ODBC Bridge driver (Bridge)
>Type 2: Native-API/partly Java driver (Native)
>Type 3: Net-protocol driver (Middleware)
>Type 4: Native-protocol driver (Pure)
 

Type 1 JDBC Driver -- JDBC-ODBC Bridge driver

The JDBC type 1 driver, also known as the JDBC-ODBC bridge, is a database driver implementation that employs the ODBC driver to connect to the database. The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API.
The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available. This driver is included in the Java 2 SDK within the sun.jdbc.odbc package. In this driver the java statements are converted to a jdbc statements. JDBC statements calls the ODBC by using the JDBC-ODBC Bridge. And finally the query is executed by the database. This driver has serious limitation for many applications.

Advantages:

1). The JDBC-ODBC Bridge allows access to almost any database, since the database’s ODBC drivers are already available.
2). Easy to connect directly to the database.

Disadvantages:

1). The client system requires the ODBC Installation to use the driver.
2). The ODBC driver needs to be installed on the client machine.
3). Not good for the Web.
4). Not suitable for applets, because the ODBC driver needs to be installed on the client.
5). Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable.
6). A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types.
 
 
 

JDBC Data Types


JDBC Data Types


JDBC Type Java Type
BITBoolean
INTEGERint
BIGINTlong
FLOATdouble
DOUBLEdouble
BINARYbyte[]
CHARString
VARCHARString
NUMERICBigDecimal
DATEjava.sql.Date
TIMEjava.sql.Timestamp
TIMESTAMPjava.sql.Timestamp
CLOBClob
BLOBBlob
ARRAYArray

What is JDBC and JDBC Architecture


What is JDBC?

JDBC stands for Java Database Connectivity. JDBC works with Java on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. JDBC is a Java API for executing SQL statements and supports basic SQL functionality. Connectivity between the Java programming language and databases.

 

JDBC Architecture

JDBC API: It is a purely Java-based API. This provides the application-to-JDBC Manager connection.
JDBC Driver API: Which communicates with with vendor-specific drivers that that perform the real communication with the database.
 

1 yard equal to how many inches,mm,cm,feet,meter,km,mile


1 yard=36 inches

1 yard=914.4 mm

1 yard=91.44 cm

1 yard=3 feet

1 yard=0.9144 meter

1 yard=0.0009144 km

1 yard=0.000568181818 miles


1 yard equal to how many inches,mm,cm,feet,meter,km,mile


1 yard=36 inches

1 yard=914.4 mm

1 yard=91.44 cm

1 yard=3 feet

1 yard=0.9144 meter

1 yard=0.0009144 km

1 yard=0.000568181818 miles


1 kilo meter equal to how many inches,mm,cm,feet,yard,meter,mile


1 km=39 370.0787 inches

1 km=1 000 000 mm

1 km=100 000 cm

1 km=3 280.8399 feet

1 km=1 093.6133 yards

1 km=1000 meter

1 km=0.621371192 miles


1 meter equal to how many inches,mm,cm,feet,yard,km,mile


1 meter=39.3700787 inches

1 meter=1000 mm

1 meter=100 cm

1 meter=3.2808399 feet

1 meter=1.0936133 yards

1 meter=0.001 km

1 meter=0.000621371192 miles



1 feet equal to how many inches,mm,cm,yard,meter,km,mile


1 feet=12 inches

1 feet=304.8 mm

1 feet=30.48 cm

1 feet=0.333333333 yards

1 feet=0.3048 meter

1 feet=0.0003048 km

1 feet=0.000189393939 miles 

 



1 centi meter equal to how many inches,mm,feet,yard,meter,km,mile


1 cm=0.393700787 inches

1 cm=10 mm

1 cm=0.032808399 feet

1 cm=0.010936133 yards

1 cm=0.01 meter

1 cm=0.00001 km (or) 1.0 X 10-5

1 cm=0.000006213711922 miles (or) 6.21371192 X 10-6miles



1 milli meter equal to how many inches,cm,feet,yard,meter,km,mile

1 mm=0.0393700787402 inches

1 mm=0.1 cm

1 mm=0.0032808399 feet

1 mm=1.0936133 yards

1 mm=0.001 meter

1 mm=0.000001 km (or) 1.0 X 10-6

1 mm=0.0000006213711922 miles (or) 6.21371192 X 10-7miles

1 Inch equal to how many mm,cm,feet,yard,meter,km,mile

1 Inch equal to how many mm,cm,feet,yard,meter,km,mile


1 Inch=25.4 mm


1 Inch=2.54 cm

1 Inch=0.0833 feet

1 Inch=0.0000277777 yards

1 Inch=0.0254 meter

1 Inch=0.0000254 km

1 Inch=1.577828283 X 10-5miles

 

 

Ascii values


The following is a listing of Ascii values.


Dec Hex Oct Char Description
0 0 000   null
1 1 001   start of heading
2 2 002   start of text
3 3 003   end of text
4 4 004   end of transmission
5 5 005   enquiry
6 6 006   acknowledge
7 7 007   bell
8 8 010   backspace
9 9 011   horizontal tab
10 A 012   new line
11 B 013   vertical tab
12 C 014   new page
13 D 015   carriage return
14 E 016   shift out
15 F 017   shift in
16 10 020   data link escape
17 11 021   device control 1
18 12 022   device control 2
19 13 023   device control 3
20 14 024   device control 4
21 15 025   negative acknowledge
22 16 026   synchronous idle
23 17 027   end of trans. block
24 18 030   cancel
25 19 031   end of medium
26 1A 032   substitute
27 1B 033   escape
28 1C 034   file separator
29 1D 035   group separator
30 1E 036   record separator
31 1F 037   unit separator
32 20 040   space
33 21 041 !  
34 22 042 "  
35 23 043 #  
36 24 044 $  
37 25 045 %  
38 26 046 &  
39 27 047 '  
40 28 050 (  
41 29 051 )  
42 2A 052 *  
43 2B 053 +  
44 2C 054 ,  
45 2D 055 -  
46 2E 056 .  
47 2F 057 /  
48 30 060 0  
49 31 061 1  
50 32 062 2  
51 33 063 3  
52 34 064 4  
53 35 065 5  
54 36 066 6  
55 37 067 7  
56 38 070 8  
57 39 071 9  
58 3A 072 :  
59 3B 073 ;  
60 3C 074 <  
61 3D 075 =  
62 3E 076 >  
63 3F 077 ?  
Dec Hex Oct Char
64 40 100 @
65 41 101 A
66 42 102 B
67 43 103 C
68 44 104 D
69 45 105 E
70 46 106 F
71 47 107 G
72 48 110 H
73 49 111 I
74 4A 112 J
75 4B 113 K
76 4C 114 L
77 4D 115 M
78 4E 116 N
79 4F 117 O
80 50 120 P
81 51 121 Q
82 52 122 R
83 53 123 S
84 54 124 T
85 55 125 U
86 56 126 V
87 57 127 W
88 58 130 X
89 59 131 Y
90 5A 132 Z
91 5B 133 [
92 5C 134 \
93 5D 135 ]
94 5E 136 ^
95 5F 137 _
96 60 140 `
97 61 141 a
98 62 142 b
99 63 143 c
100 64 144 d
101 65 145 e
102 66 146 f
103 67 147 g
104 68 150 h
105 69 151 i
106 6A 152 j
107 6B 153 k
108 6C 154 l
109 6D 155 m
110 6E 156 n
111 6F 157 o
112 70 160 p
113 71 161 q
114 72 162 r
115 73 163 s
116 74 164 t
117 75 165 u
118 76 166 v
119 77 167 w
120 78 170 x
121 79 171 y
122 7A 172 z
123 7B 173 {
124 7C 174 |
125 7D 175 }
126 7E 176 ~
127 7F 177 DEL