Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

JDBC Interview Questions and Answers For Freshers Part-5

Be First!

jdbc41.How will you insert multiple rows into a database in a single transaction?
Follow steps as below

//turn off the implicit commit
Connection.setAutoCommit(false);
//..your insert/update/delete goes here
Connection.Commit();
//a new transaction is implicitly started.

42.When will you get the message “No Suitable Driver”?
When a Connection request is issued, the DriverManager asks each loaded driver if it understands the URL sent. When the URL passed is not properly constructed, then the “No Suitable Driver” message is returned.

43.What is the difference between execute, executeQuery, executeUpdate?
boolean execute() – Executes the any kind of SQL statement.

ResultSet executeQuery() – This is used generally for reading the content of the database. The output will be in the form of ResultSet. Generally SELECT statement is used.

int executeUpdate() – This is generally used for altering the databases. Generally DROP TABLE or DATABASE, INSERT into TABLE, UPDATE TABLE, DELETE from TABLE statements will be used in this. The output will be in the form of int which denotes the number of rows affected by the query.

44.Why do you have to close database connections in Java?
You need to close the resultset, the statement and the connection. If the connection has come from a pool, closing it actually sends it back to the pool for reuse. We can do this in the finally{} block, such that if an exception is thrown, you still get the chance to close this.

45.What is the use of blob, clob datatypes in JDBC?
These are used to store large amount of data into database like images, movie etc which are extremely large in size.

46.Resultset is an interface, how does it support rs.Next()?
Every vendor of Database provides implementation of ResultSet & other interfaces, through the Driver.

47.What is Connection Pooling?
Connection Pooling is a technique used for reuse of physical connections and reduced overhead for your application. Connection pooling functionality minimizes expensive operations in the creation and closing of sessions.Database vendor’s help multiple clients to share a cached set of connection objects that provides access to a database. Clients need not create a new connection everytime to interact with the database.

48.How do you implement connection pooling?
If you use an application server like WebLogic, WebSphere, jBoss, Tomcat. , then your application server provides the facilities to configure for connection pooling. If you are not using an application server then components like Apache Commons DBCP Component can be used.

49.Out of byte[] or a java.sql.Blob, which has best performance when used to manipulate data from database?
java.sql.Blob has better performance as it does not extract any data from the database until you explicitly ask it to.

50.Out of String or a java.sql.Clob, which has best performance when used to manipulate data from database?
java.sql.Clob has better performance as it does not extract any data from the database until you explicitly ask it to.

(178)

Previous
Next

Leave a Reply