|
Technical Interview Questions
Javascript Interview Questions
Oracle Interview Questions
J2EE Interview Questions
C++
Interview Questions
XML
Interview Questions
EJB
Interview Questions
JSP
Interview Questions
.........More
Programming Source Codes
Java Source Codes
Html Source Codes
CSS Source Codes
C Source Codes
.........More
Soft Skills
Communication Skills
Leadership Skills
.........More
|
|
JDBC Interview Questions and Answers
What isolation level is used by the DBMS when
inserting, updating and selecting rows from a database?
The answer depends on both your code and the DBMS. If
the program does not explicitly set the isolation level,
the DBMS default is used. You can determine the default
using DatabaseMetaData.getDefaultTransactionIsolation()
and the level for the current Connection with
Connection.getTransactionIsolation(). If the default is
not appropriate for your transaction, change it with
Connection.setTransactionIsolation(int level).
How can I determine the isolation levels supported by my
DBMS?
Use
DatabaseMetaData.supportsTransactionIsolationLevel(int
level).
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 assume that your proxy is set to accept http requests
only on port 80. If you want to have a local class
behind the proxy connect to the database for you, then
you need a servlet/JSP to receive an HTTP request and
use the local class to connect to the database and send
the response back to the client.
You could also use RMI where your remote computer class
that connects to the database acts as a remote server
that talks RMI with the clients. if you implement this,
then you will need to tunnel RMI through HTTP which is
not that hard.
In summary, either have a servlet/JSP take HTTP
requests, instantiate a class that handles database
connections and send HTTP response back to the client or
have the local class deployed as RMI server and send
requests to it using RMI.
How do I receive a ResultSet from a stored procedure?
Stored procedures can return a result parameter, which
can be a result set. For a discussion of standard JDBC
syntax for dealing with result, IN, IN/OUT and OUT
parameters, see Stored Procedures.
How can I write to the log used by DriverManager and
JDBC drivers?
The simplest method is to use
DriverManager.println(String message), which will write
to the current log.
How can I get or redirect the log used by DriverManager
and JDBC drivers?
As of JDBC 2.0, use DriverManager.getLogWriter() and
DriverManager.setLogWriter(PrintWriter out). Prior to
JDBC 2.0, the DriverManager methods getLogStream() and
setLogStream(PrintStream out) were used. These are now
deprecated.
What does it mean to "materialize" data?
This term generally refers to Array, Blob and Clob data
which is referred to in the database via SQL locators
"Materializing" the data means to return the actual data
pointed to by the Locator.
For Arrays, use the various forms of getArray() and
getResultSet().
For Blobs, use getBinaryStream() or getBytes(long pos,
int length).
For Clobs, use getAsciiStream() or getCharacterStream().
Why do I have to reaccess the database for Array, Blob,
and Clob data?
Most DBMS vendors have implemented these types via the
SQL3 Locator type
Some rationales for using Locators rather than directly
returning the data can be seen most clearly with the
Blob type. By definition, a Blob is an arbitrary set of
binary data. It could be anything; the DBMS has no
knowledge of what the data represents. Notice that this
effectively demolishes data independence, because
applications must now be aware of what the Blob data
actually represents. Let's assume an employee table that
includes employee images as Blobs.
Say we have an inquiry program that presents multiple
employees with department and identification
information. To see all of the data for a specific
employee, including the image, the summary row is
selected and another screen appears. It is only at this
pont that the application needs the specific image. It
would be very wasteful and time consuming to bring down
an entire employee page of images when only a few would
ever be selected in a given run.
Now assume a general interactive SQL application. A
query is issued against the employee table. Because the
image is a Blob, the application has no idea what to do
with the data, so why bring it down, killing performance
along the way, in a long running operation?
Clearly this is not helpful in those applications that
need the data everytime, but these and other
considerations have made the most general sense to DBMS
vendors.
What is an SQL Locator?
A Locator is an SQL3 data type that acts as a logical
pointer to data that resides on a database server. Read
"logical pointer" here as an identifier the DBMS can use
to locate and manipulate the data. A Locator allows some
manipulation of the data on the server. While the JDBC
specification does not directly address Locators, JDBC
drivers typically use Locators under the covers to
handle Array, Blob, and Clob data types.
How do I set properties for a JDBC driver and where are
the properties stored?
A JDBC driver may accept any number of properties to
tune or optimize performance for the specific driver.
There is no standard, other than user and password, for
what these properties should be. Therefore, the
developer is dependent on the driver documentation to
automatically pass properties. For a standard dynamic
method that can be used to solicit user input for
properties, see What properties should I supply to a
database driver in order to connect to a database?
In addition, a driver may specify its own method of
accepting properties. Many do this via appending the
property to the JDBC Database URL. However, a JDBC
Compliant driver should implement the connect(String url,
Properties info) method. This is generally invoked
through DriverManager.getConnection(String url,
Properties info).
The passed properties are ( probably ) stored in
variables in the Driver instance. This, again, is up to
the driver, but unless there is some sort of driver
setup, which is unusual, only default values are
remembered over multiple instantiations.
What is the JDBC syntax for using a literal or variable
in a standard Statement?
First, it should be pointed out that PreparedStatement
handles many issues for the developer and normally
should be preferred over a standard Statement.
Otherwise, the JDBC syntax is really the same as SQL
syntax. One problem that often affects newbies ( and
others ) is that SQL, like many languages, requires
quotes around character ( read "String" for Java )
values to distinguish from numerics. So the clause:
"WHERE myCol = " + myVal
is perfectly valid and works for numerics, but will fail
when myVal is a String. Instead use:
"WHERE myCol = '" + myVal + "'"
if myVal equals "stringValue", the clause works out to:
WHERE myCol = 'stringValue'
You can still encounter problems when quotes are
embedded in the value, which, again, a PreparedStatement
will handle for you.
How do I check in my code whether a maximum limit of
database connections have been reached?
Use DatabaseMetaData.getMaxConnections() and compare to
the number of connections currently open. Note that a
return value of zero can mean unlimited or,
unfortunately, unknown. Of course,
driverManager.getConnection() will throw an exception if
a Connection can not be obtained.
Why do I get UnsatisfiedLinkError when I try to use my
JDBC driver?
The first thing is to be sure that this does not occur
when running non-JDBC apps. If so, there is a faulty JDK/JRE
installation. If it happens only when using JDBC, then
it's time to check the documentation that came with the
driver or the driver/DBMS support. JDBC driver types 1
through 3 have some native code aspect and typically
require some sort of client install. Along with the
install, various environment variables and path or
classpath settings must be in place. Because the
requirements and installation procedures vary with the
provider, there is no reasonable way to provide details
here. A type 4 driver, on the other hand, is pure Java
and should never exhibit this problem. The trade off is
that a type 4 driver is usually slower.
Page Numbers :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Java Interview
Questions for more Java Interview Questions with answers
Check
Structs Interview
Questions for more Structs Interview Questions with answers
Check
Servlet Interview
Questions for more Servlet Interview Questions with answers
|