Saturday, 25 August 2012
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
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 |
---|---|
BIT | Boolean |
INTEGER | int |
BIGINT | long |
FLOAT | double |
DOUBLE | double |
BINARY | byte[] |
CHAR | String |
VARCHAR | String |
NUMERIC | BigDecimal |
DATE | java.sql.Date |
TIME | java.sql.Timestamp |
TIMESTAMP | java.sql.Timestamp |
CLOB | Clob |
BLOB | Blob |
ARRAY | Array |
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.
|
|
Subscribe to:
Posts (Atom)