Saturday, February 3, 2007

which is the best driver among the 4 jdbc drivers?

1.
a. Type 4 driver is the best driver among 4 drivers because it need not be load other API's, because the code is developed only in java language, so other language API's are not need.

b. Type 4 is the best driver because it directly interact with database without any usage od intermediate serversor other technology.Because of this reason Type-4 driver is also called Thin Driver

c. . Use Type 4 driver for applet to database communication.

2. Use Type 2 driver for two tiered applications for communication between java client and the database that gives better performance when compared to Type1 driver

3. Use Type 1 driver if your database doesn't support a driver. This is rare situation because almost all major databases support drivers or you will get them from third party vendors.

4.Use Type 3 driver to communicate between client and proxy server ( weblogic, websphere etc) for three tiered applications that gives better performance when compared to Type 1 & 2 drivers.

there, the order in which the drivers can be used is 4213,

SOURCE : www.referjava.com

why do we use prepared statement when statement is there

a. Prepared statement is a precompiled statement, it is mailnly used for the speed up the prcoss of inserting/updating/deleting when there is a bulk processing.

b. Actually when u submit a simple statement to the database, at first the DBMS parses it and sends it back with the result, so again when u send the same statement again the DBMS server parses it and sends back the result so here a lot of time is wasted and because the statement is again parsed though it has been sent twice or thrice it consumes a lot of time and response will be slow. Prepared Statement is used when u want to execute a statement object many times. When u submits a PreparedStatement the DBMS server parses it and creates an execution plan. This e-plan can be used when u again send the same statement to the database. That is the DBMS server zest executes the compiled statement rather that executing it from first, hence we get a precompiled statement. And also the advantage of using this PreparedStatement is it is used to send dynamic sql statements, which u can give values later than giving the values at the time of creation.

c. Prepared Statement is Pre-compiled class, but Statement is not.So in PreparedStatement the execution will be faster.

SOURCE : www.referjava.com

how to store images in a database?

a. We can store the image in the database using the blob (binary large object) data type, where the image is stored in the form of the streams...

b. Using binary streams (i.e. getBinaryStream () ,setBinaryStream()).But it is not visable in database ,it is stored in form of bytes ,to make it visable we have to use any one frontend tool.

SOURCE : www.referjava.com

How to get the resultset of stored Procedure ?

a. By invoking the getObject on the CallableStatement.CallableStatement
proc = conn.prepareCall("{ ? = call " + functionSql + "
}");proc.registerOutParameter(1, Types.OTHER); proc.execute();ResultSet results =
(ResultSet) proc.getObject(1);

b. Involve getResultSet() method of the callableStatement object that is
inherited from java.sql.Statement interface.

SOURCE : www.referjava.com

Difference between Type-2 and Type-3 driver ?

a. Type 2 driver is part Native-part Java driver. It is also one of the thin drivers. After the java calls are converted into JDBC calls by using the JDBC API, and those calls use the vendor specific API and connected to Database to get the results.
Type 3 is Medium Access Sub Layer driver. After the calls are converted to JDBC calls by using JDBC API, they are forwarded to another driver(either type 2 or type 4) and from there it goes to the Database to get the results.

b. Type-2 driver is Part Java Part Native Driver. This driver is a mixture of Jdbc driver and Vendor speciifc driver . You not only use ODBC to communicate with DataBase. You can also use Vendor specif Apis like Oracle Call Level Interface (OCI) that is supplied by Oracle.When an application is sent to the Jdbc driver this driver sends this request to Vendor specific api and that inturn communicates with the Database.
Type-3 driver is Intermediate Access Protocol Driver where as in this case when an application is sent to the JDBC Driver and that is sent to another intermediate acess servers and that inturn is sent to another native driver (can be an Type-2 driver) and then the request is sent to Database.

SOURCE : www.referjava.com

What is Connection Pooling?

a. Connection pooling is the process of reusing the database connections created between the application and the database, by then increasing the performance of the application.
Suppose, that there is table in the database, called 'employer', if a objects asks the application server to create a connection between the table and the object, the appServer creates, but it does not throw away the connection, it keeps the connection information in a pool, if again the object requires to connect to the table, it doesn't require to create a new connection as the connection available in the connection pool can be reused. Hence increase in performance.

b. Connection Pooling is a technique used for sharing the server resources among requested clients. It was pioneered by database vendors to allow multiple clients to share a cached set of connection objects that provides access to a database.

c. Connection pooling is a place where a set of connections is kept and is used by the different programers with out creating conncections tithe database (it means there is a ready made connection a available for the programmers where he can use). After using the connection he can send back that connection to the connection pool. Number of connections in connection pool may vary.

d. Getting connection and disconnecting are tasks by itself, which costs to the application performance, so we should avoid it. To be more precise, depending of the Max & Min connections parm set in the specific Appserver config, it intially either gets the min set of ready to connections or would be request based till the max connections are used. Once DB operations are done, the free DB connections are re-used.

e. Getting connection and disconnecting are tasks by itself, which costs to the application perfomance, so we should aovid it. To be more precise, depending of the Max & Min connections parm set in the specific Appserver config, it intially either gets the min set of ready to connections or would be request based till the max connections are used. Once DB operations are done, the free DB connections are re-used.

f. Connection pooling means set of connections is available to connect, after use this connection, disconnect it then others can use it. It reduces the time, and it can be eusable. User can use any number of connections.

SOURCE : www.referjava.com

Diff btw TYPE_SCROLL_INSENSITIVE, and TYPE_SCROLL_SENSITIVE?

a result set that is TYPE_SCROLL_INSENSITIVE does not reflect
changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE
does.

SOURCE : www.referjava.com