YouTube Icon

Interview Questions.

Top 50 Jdbc Interview Questions - Jul 26, 2022

fluid

Top 50 Jdbc Interview Questions

Q1. What Are The Licensing Terms?

The OSI-accredited CDDL license is being used for project GlassFish which lets in builders to view, use, edit, and modify the code, and distribute it or use it in production. Portions of this code aren't yet to be had in source form. Because of this, a few quantities are presently also underneath a Binary Distribution License. As time goes on, we’ll make extra of the code to be had, with the eventual intention of creating all of the code available, and putting off the Binary Distribution license. This isn’t some form of evil plot – it’s difficult work shifting stuff out into an Open environment, we anticipate to have a roadmap for our timing for this posted by the quit of the Summer.

People who need to redistribute a build of our utility server do no longer have a license to use the CTS nor can they use the Java Compatibility brand. They may additionally choose to sign a JDL industrial license and skip the CTS which would then allow them to distribute the code and use the Java Compatibility emblem.

Q2. What Is Session?

The session is an object used by a servlet to music a person's interaction with a Web software throughout multiple HTTP requests.

Q3. What Does It Mean To "materialize" Data?

This time period generally refers to Array, Blob and Clob facts that's referred to inside the database thru SQL locators "Materializing" the facts me to return the real information pointed to by the Locator.

For Arrays, use the various kinds of getArray() and getResultSet().

For Blobs, use getBinaryStream() or getBytes(long pos, int period).

For Clobs, use getAsciiStream() or getCharacterStream().

Q4. Connecting To A Database Through The Proxy I Want To Connect To Remote Database Using A Program That Is Running In The Local Network Behind The Proxy. Is That Possible?

I expect that your proxy is set to just accept http requests most effective on port 8@If you want to have a local magnificence at the back of the proxy connect to the database for you, then you definitely need a servlet/JSP to get hold of an HTTP request and use the nearby elegance to connect to the database and send the reaction lower back to the patron.

You may also use RMI in which your far flung laptop elegance that connects to the database acts as a faraway server that talks RMI with the clients. In case you implement this, then you may need to tunnel RMI thru HTTP which is not that tough.

In summary, either have a servlet/JSP take HTTP requests, instantiate a category that handles database connections and ship HTTP reaction returned to the consumer or have the nearby elegance deployed as RMI server and send requests to it using RMI.

Q5. If A Servlet Is Not Properly Initialized, What Exception May Be Thrown?

During initialization or carrier of a request, the servlet example can throw an UnavailableException or a ServletException.

Q6. What Is Cdma One ?

Also realize as IS-ninety five, CDMA One is a 2d era wi-fi era. Supports speeds from 14.4Kbps to 115K bps.

Q7. I Made My Class Cloneable But I Still Get Can't Access Protected Method Clone. Why?

Some of the Java books suggest that all you have to do so that you can have your class help clone() is put into effect the Cloneable interface. Not so. Perhaps that turned into the reason in some unspecified time in the future, however that’s not the manner it works currently. As it stands, you need to implement your very own public clone() method, even though it doesn’t do anything special and simply calls outstanding.Clone().

Q8. What Is Connection Pooling?

Connection pooling is a way used for sharing server assets amongst inquiring for customers. Connection pooling will increase the overall performance of Web programs by reusing lively database connections in preference to creating a new connection with every request. Connection pool supervisor continues a pool of open database connections.

Q9. What Is Project Glassfish?

GlassFish is the name for the open supply development mission for building a Java EE five utility server. It is primarily based on the source code for Sun Java System Application Server PE 9 donated with the aid of Sun Microsystems and TopLink endurance code donated via Oracle. This venture provides a dependent process for developing a excessive exceptional application server that makes new capabilities available quicker than ever before. It is the response to Java builders who want get admission to to the source code and the capacity to contribute to the development of Sun’s next generation utility server that is based totally on GlassFish. This assignment is designed to encourage communique between Sun and Oracle engineers and the network and could permit all developers to participate inside the software server development system.

Q10. How Do I Receive A Resultset From A Stored Procedure?

Stored tactics can go back a end result parameter, which can be a end result set. For a dialogue of popular JDBC syntax for handling result, IN, IN/OUT and OUT parameters, see Stored Procedures.

Q11. Can I Use Jdbc To Execute Non-preferred Features That My Dbms Provides?

The wer is a qualified yes. As discussed beneath SQL Conformance: "One way the JDBC API deals with this trouble is to allow any question string to be passed through to an underlying DBMS driver. This me that an application is loose to apply as a great deal SQL capability as preferred, but it runs the danger of receiving an errors on a few DBMSs. In reality, an utility question may be something other than SQL, or it could be a specialised spinoff of SQL designed for precise DBMSs (for file or photo queries, for instance)."

Clearly this me either giving up portability or checking the DBMS presently used earlier than invoking unique operations.

Q12. Db2 Universal Claims To Support Jdbc 2.Zero, But I Can Only Get Jdbc 1.Zero Functionality. What Can I Do?

DB2 Universal defaults to the 1.Zero motive force. You need to run a unique program to allow the 2.0 driver and JDK support. 

Q13. How Do I Extract A Blob From A Database?

A BLOB (Binary Large OBject) is largely an array of bytes (byte[]), stored in the database. You extract the information in two steps:

Call the getBlob approach of the Statement magnificence to retrieve a java.Sq..Blob object.

Call both getBinaryStream or getBytes inside the extracted Blob item to retrieve the java byte[] which is the Blob object.

Note that a Blob is largely a pointer to a byte array (called LOCATOR in database-talk), so the java.Square.Blob object basically wraps a byte pointer. Thus, you have to extract all information from the database blob earlier than calling commit or

  <div align="center">

non-public void runGetBLOB()

strive

 // Prepare a Statement:

PreparedStatement stmnt = conn.PrepareStatement("pick out aBlob from BlobTable");

// Execute

ResultSet rs = stmnt.ExecuteQuery();

while(rs.Next())

try

// Get as a BLOB

Blob aBlob = rs.GetBlob(1);

byte[] allBytesInBlob = aBlob.GetBytes(1, (int) aBlob.Period());

trap(Exception ex)

// The driving force could not manage this as a BLOB...

// Fallback to default (and slower) byte[] coping with

byte[] bytes = rs.GetBytes(1);

 

// Close resources  rs.Close();

stmnt.Close();

catch(Exception ex)

this.Log("Error while trying to read BLOB: " + ex);

</div>

Q14. Why Do I Get Unsatisfiedlinkerror When I Try To Use My Jdbc Driver?

The first component is to make sure that this doesn't arise when walking non-JDBC apps. If so, there's a defective JDK/JRE set up. If it takes place handiest whilst the use of JDBC, then it is time to test the documentation that came with the driver or the motive force/DBMS support. JDBC driving force sorts 1 through 3 have a few native code aspect and usually require some form of purchaser installation. Along with the installation, various surroundings variables and path or classpath settings ought to be in area. Because the requirements and set up tactics vary with the issuer, there may be no reasonable manner to provide info right here. A type four motive force, then again, is pure Java and ought to in no way showcase this problem. The change off is that a type 4 driver is normally slower.

Q15. What Is New In Jdbc 2.0?

With the JDBC 2.Zero API, you may be able to do the following:

Scroll forward and backward in a end result set or move to a specific row (TYPE_SCROLL_ SENSITIVE, preceding(), ultimate(), absolute(), relative(), etc.) Make updates to database tables the use of techniques in the Java programming language in place of the usage of SQL commands.(updateRow(), insertRow(), deleteRow(), and so forth.) Send a couple of SQL statements to the database as a unit, or batch (addBatch(), executeBatch()) Use the brand new SQL3 datatypes as column values like Blob, Clob, Array, Struct, Ref.

Q16. What Is Jdbc Driver Interface?

The JDBC Driver interface gives vendor-specific implementations of the summary classes supplied by means of the JDBC API. Each vendor motive force ought to provide implementations of the java.Square.Connection, Statement, Prepared Statement,  CallableStatement, ResultSet and Driver.

Q17. What Does A Thread Enter When It Terminates Its Processing?

When a thread terminates its processing, it enters the useless kingdom.

Q18. Can We Implement An Interface In A Jsp?

No

Q19. What Is The Genericservlet Class?

GenericServlet makes writing servlets less difficult. To write a regular servlet, all you need to do is to override the abstract service technique.

Q20. How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database?

You can use a consumer-side Refresh or Server Push.

Q21. How Do I Disallow Null Values In A Table?

Null functionality is a column integrity constraint, typically implemented at desk introduction time. Note that a few databases might not permit the constraint to be implemented after desk introduction. Most databases permit a default cost for the column as well. The following SQL assertion presentations the NOT NULL constraint:

  CREATE TABLE CoffeeTable ( 

Type VARCHAR(25) NOT NULL, 

Pounds INTEGER NOT NULL, 

Price NUMERIC(5, 2) NOT NULL 

)

Q22. What Is The Difference Between Requestdispatcher And Sendredirect?

RequestDispatcher: server-side redirect with request and response gadgets.

SendRedirect : Client-facet redirect with new request and response gadgets.

Q23. The Code In A Finally Clause Will Never Fail To Execute, Right?

Using System.Go out(1); in strive block will no longer permit subsequently code to execute.

Q24. How Does A Custom Rowsetreader Get Called From A Cachedrowset?

The Reader ought to be registered with the CachedRowSet the usage of Cached RowSet .SetReader javax.Square. RowSet Reader reader). Once this is performed, a call to Cached RowSet. Execute() will, among different matters, invoke the readData approach.

Q25. Explain The Concepts Of Tomcat Servlet Container?

A servlet container is a specialized net server that supports servlet execution.

It combines the basic capability of a web server with sure Java/servlet specific optimizations and extensions (consisting of an included Java runtime environment, and the potential to routinely trlate specific URLs into servlet requests).

Individual servlets are registered with a servlet field, providing the box with facts along with the capability, the URL used for identity.

The servlet box then initializes the servlet as essential and grants requests to the servlet as they come.

Many bins can dynamically add and do away with servlets from the device, allowing new servlets to speedy be deployed or eliminated with out affecting other servlets going for walks from the identical box.

Servlet packing containers also are referred to as web containers or internet engines.

Q26. What Are The Standard Isolation Levels Defined By Jdbc?

The values are described inside the elegance java.Sq..Connection and are:

TRANSACTION_NONE

TRANSACTION_READ_COMMITTED

TRANSACTION_READ_UNCOMMITTED

TRANSACTION_REPEATABLE_READ

TRANSACTION_SERIALIZABLE

Any given database may not assist all of those stages.

Q27. What Driver Should I Use For Scalable Oracle Jdbc Applications?

Sun recommends the use of the thin ( kind four ) motive force.

On single processor machines to keep away from JNI overhead.

On more than one processor machines, particularly running Solaris, to avoid synchronization bottlenecks.

Q28. How Can I Send User Authentication Information While Makingurlconnection?

You’ll want to use HttpURLConnection.SetRequestProperty and set all the suitable headers to HTTP authorization.

Q29. How Can I Connect From An Applet To A Database On The Server?

There are two methods of connecting to a database at the server side.

The hard manner. Untrusted applets cannot touch the hard disk of a laptop. Thus, your applet can not use native or other nearby documents (together with JDBC database drivers) in your tough power. The first opportunity solution is to create a digitally signed applet which may use locally installed JDBC drivers, able to connect directly to the database on the server facet.

The clean way. Untrusted applets may most effective open a network connection to the server from which they had been downloaded. Thus, you need to place a database listener (both the database itself, or a middleware server) at the server node from which the applet was downloaded. The applet could open a socket connection to the middleware server, located at the same laptop node as the webserver from which the applet turned into downloaded. The middleware server is used as a mediator, connecting to and extract facts from the database.

Q30. What's The Best Way, In Terms Of Performance, To Do Multiple Insert/update Statements, A Preparedstatement Or Batch Updates?

Because PreparedStatement objects are precompiled, their execution can be quicker than that of Statement objects. Consequently, an SQL declaration that is performed often is often created as a PreparedStatement item to growth efficiency. A CallableStatement item affords a way to call stored techniques in a widespread manner for all DBMSes. Their execution can be faster than that of PreparedStatement object. Batch updates are used whilst you want to execute multiple statements together. Actually, there may be no warfare right here. While it relies upon at the driver/DBMS engine as to whether or now not you'll get an real performance benefit from batch updates, Statement, PreparedStatement, and CallableStatement can all execute the addBatch() approach.

Q31. What Is The Jdbc?

Java Database Connectivity (JDBC) is a wellknown Java API to have interaction with relational databases form Java. JDBC has set of instructions and interfaces which could use from Java software and communicate to database without mastering RDBMS information and the use of Database Specific JDBC Drivers.

Q32. What Is A Data Source

A DataSource magnificence brings some other degree of abstraction than immediately the use of a connection item. Data source can be referenced with the aid of JNDI. Data Source can also point to RDBMS, file System , any DBMS etc.

Q33. What Is The Difference Between Difference Between Doget() And Dopost()?

A doGet() technique is restrained with 2k of facts to be sent, and doPost() method would not have this obstacle.

DoPost() method call doesn't need a long textual content tail after a servlet name in a request. All parameters are saved in a request itself, no longer in a request string, and it's impossible to guess the information trmitted to a servlet simplest searching at a request string.

Q34. How Can I Determine Whether A Statement And Its Resultset Will Be Closed On A Commit Or Rollback?

Use the DatabaseMetaData methods supportsOpen StatementsAcrossCommit() and supports Open Statements Across Rollback().

Q35. What Is Rowset?

A RowSet is an object that encapsulates a set of rows from both Java Database Connectivity (JDBC) result units or tabular facts sources like a report or spreadsheet. RowSets guide thing-based improvement fashions like JavaBe, with a general set of residences and an event notification .

Q36. How Do I Configure Tomcat To Work With Iis And Ntlm?

Follow the usual instructions for when the isapi_redirector.Dll

Configure IIS to use "incorporated home windows safety".

In server.Xml, make certain you disable tomcat authentication.

Q37. How Can I Determine The Isolation Levels Supported By My Dbms?

Use DatabaseMetaData.SupportsTractionIsolationLevel(int level).

Q38. What Is The Difference Between Callling A Requestdispatcher Using Servletrequest And Servletcontext?

We can provide relative URL while we use ServletRequest and now not even as using ServletContext.

Q39. How Applet Restrictions Affect Jdbc? Explain.

As you have discovered, a Java applet can simplest connect to the server from which the person downloaded the applet. In addition, some browser, which include Netscape, do now not permit an applet write or study neighborhood files. Therefore, a database applet can't write seek end result to a file or insert facts right into a database. You have to take these restrictions into attention when you layout an applet that is going to get entry to a database.

Q40. What Are The Common Tasks Of Jdbc?

Create an instance of a JDBC driver or load JDBC drivers through jdbc.Drivers

Register a driver

Specify a database

Open a database connection

Submit a question

Receive effects

Process consequences

Q41. What Are The Different Types Of Rowset ?

There are two styles of RowSet are there. They are:

Connected - A related RowSet object connects to the database once and remains linked until the software terminates.

Disconnected - A disconnected RowSet item connects to the database, executes a query to retrieve the statistics from the database and then closes the relationship. A application may additionally trade the facts in a disconnected RowSet at the same time as it is disconnected. Modified facts can be updated inside the database after a disconnected RowSet reestablishes the connection with the database.

Q42. Which Interface Must Be Implemented By All Servlets?

Servlet interface.

Q43. What Is Pessimistic Concurrency?

With a pessimistic technique, locks are used to make certain that no users, apart from the only who holds the lock, can update statistics. It's generally defined that the time period pessimistic is used because the expectation is that many users will try to update the same records, so one is pessimistic that an replace can be capable to finish well. Locks may be obtained, depending on the DBMS seller, robotically thru the selected Isolation Level. Some carriers additionally put in force 'Select... For Update', which explicitly acquires a lock.

Q44. What Is The Difference Between The Getrequestdispatcher(string Path) Method Of Javax.Servlet.Servletrequest Interface And Javax.Servlet.Servletcontext Interface?

The getRequestDispatcher(String course) approach of javax.Servlet.ServletRequest interface accepts parameter the route to the resource to be blanketed or forwarded to, which may be relative to the request of the calling servlet. If the direction starts with a "/" it's far interpreted as relative to the contemporary context root.

The getRequestDispatcher(String direction) technique of javax.Servlet.ServletContext interface can't accepts relative paths. All course must sart with a "/" and are interpreted as relative to curent context root.

Q45. How Can I Get Data From Multiple Resultsets?

With sure database systems, a saved system can return multiple end result sets, a couple of update counts, or some mixture of each. Also, in case you are offering a consumer with the capacity to enter any SQL statement, you don't know in case you are going to get a ResultSet or an replace rely lower back from each declaration, with out analyzing the contents. The Statement.Execute() technique enables in these instances.

Method Statement.Execute() returns a boolean to inform you the sort of reaction:

real indicates subsequent result is a ResultSet

Use Statement.GetResultSet to get the ResultSet

fake shows subsequent end result is an update count

Use Statement.GetUpdateCount to get the update matter

false additionally shows no extra effects

Update count number is -1 when no more results (commonly 0 or high quality)

After processing each reaction, you use Statement.GetMoreResults to test for extra results, again returning a boolean. The following demonstrates the processing of more than one end result units:

  boolean result = stmt.Execute(" ... ");

int updateCount = stmt.GetUpdateCount();

at the same time as (end result (updateCount != -1)) 

if(result) 

ResultSet r = stmt.GetResultSet();

// method result set

 else if(updateCount != -1) 

// method update count

result = stmt.GetMoreResults(); 

updateCount = stmt.GetUpdateCount();

Q46. What Is New In Servletrequest Interface ? (servlet 2.Four)

The following techniques were delivered to ServletRequest 2.4 model:

  public int getRemotePort()

public java.Lang.String getLocalName()

public java.Lang.String getLocalAddr()

public int getLocalPort()

Q47. How Many Types Of Jdbc Drivers Are Present And What Are They?

There are 4 styles of JDBC Drivers

JDBC-ODBC Bridge Driver

Native API Partly Java Driver

Network protocol Driver

JDBC Net pure Java Driver

Q48. What Is Servletcontext?

ServletContext is an Interface that defines a set of strategies that a servlet makes use of to speak with its servlet field, for example, to get the MIME form of a record, dispatch requests, or write to a log file. There is one context in keeping with "internet utility" in step with Java Virtual Machine. (A "net utility" is a set of servlets and content material set up beneath a selected subset of the server's URL namespace together with /catalog and in all likelihood set up thru a .Battle file.)

Q49. Can We Use The Constructor, Instead Of Init(), To Initialize Servlet?

Yes , of course you may use the constructor in place of init(). There's not anything to forestall you. But you shouldn't. The unique reason for init() became that historic versions of Java could not dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That not applies, however servlet boxes nonetheless will handiest call your no-arg constructor. So you may not have get admission toincludes(theParameter); (which matches in Servlet 2.3+)




CFG