|
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
Can I set up a connection pool with multiple user IDs?
The single ID we are forced to use causes problems when
debugging the DBMS.
Since the Connection interface ( and the underlying DBMS
) requires a specific user and password, there's not
much of a way around this in a pool. While you could
create a different Connection for each user, most of the
rationale for a pool would then be gone. Debugging is
only one of several issues that arise when using pools.
However, for debugging, at least a couple of other
methods come to mind. One is to log executed statements
and times, which should allow you to backtrack to the
user. Another method that also maintains a trail of
modifications is to include user and timestamp as
standard columns in your tables. In this last case, you
would collect a separate user value in your program.
How can I protect my database password ? I'm writing a
client-side java application that will access a database
over the internet. I have concerns about the security of
the database passwords. The client will have access in
one way or another to the class files, where the
connection string to the database, including user and
password, is stored in as plain text. What can I do to
protect my passwords?
This is a very common question.
Conclusion: JAD decompiles things easily and obfuscation
would not help you. But you'd have the same problem with
C/C++ because the connect string would still be visible
in the executable.
SSL JDBC network drivers fix the password sniffing
problem (in MySQL 4.0), but not the decompile problem.
If you have a servlet container on the web server, I
would go that route (see other discussion above) then
you could at least keep people from reading/destroying
your mysql database.
Make sure you use database security to limit that app
user to the minimum tables that they need, then at least
hackers will not be able to reconfigure your DBMS
engine.
Aside from encryption issues over the internet, it seems
to me that it is bad practice to embed user ID and
password into program code. One could generally see the
text even without decompilation in almost any language.
This would be appropriate only to a read-only database
meant to be open to the world. Normally one would either
force the user to enter the information or keep it in a
properties file.
Detecting Duplicate Keys I have a program that inserts
rows in a table. My table has a column 'Name' that has a
unique constraint. If the user attempts to insert a
duplicate name into the table, I want to display an
error message by processing the error code from the
database. How can I capture this error code in a Java
program?
A solution that is perfectly portable to all databases,
is to execute a query for checking if that unique value
is present before inserting the row. The big advantage
is that you can handle your error message in a very
simple way, and the obvious downside is that you are
going to use more time for inserting the record, but
since you're working on a PK field, performance should
not be so bad.
You can also get this information in a portable way, and
potentially avoid another database access, by capturing
SQLState messages. Some databases get more specific than
others, but the general code portion is 23 - "Constraint
Violations". UDB2, for example, gives a specific such as
23505, while others will only give 23000.
What driver should I use for scalable Oracle JDBC
applications?
Sun recommends using the thin ( type 4 ) driver.
* On single processor machines to avoid JNI overhead.
* On multiple processor machines, especially running
Solaris, to avoid synchronization bottlenecks.
Can you scroll a result set returned from a stored
procedure? I am returning a result set from a stored
procedure with type SQLRPGLE but once I reach the end of
the result set it does not allow repositioning. Is it
possible to scroll this result set?
A CallableStatement is no different than other
Statements in regard to whether related ResultSets are
scrollable. You should create the CallableStatement
using Connection.prepareCall(String sql, int
resultSetType, int resultSetConcurrency).
How do I write Greek ( or other non-ASCII/8859-1 )
characters to a database?
From the standard JDBC perspective, there is no
difference between ASCII/8859-1 characters and those
above 255 ( hex FF ). The reason for that is that all
Java characters are in Unicode ( unless you
perform/request special encoding ). Implicit in that
statement is the presumption that the data store can
handle characters outside the hex FF range or interprets
different character sets appropriately. That means
either:
* The OS, application and database use the same code
page and character set. For example, a Greek version of
NT with the DBMS set to the default OS encoding.
* The DBMS has I18N support for Greek ( or other
language ), regardless of OS encoding. This has been the
most common for production quality databases, although
support varies. Particular DBMSes may allow setting the
encoding/code page/CCSID at the database, table or even
column level. There is no particular standard for
provided support or methods of setting the encoding. You
have to check the DBMS documentation and set up the
table properly.
* The DBMS has I18N support in the form of Unicode
capability. This would handle any Unicode characters and
therefore any language defined in the Unicode standard.
Again, set up is proprietary.
How can I insert images into a Mysql database?
This code snippet shows the basics:
File file = new File(fPICTURE);
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps =
ConrsIn.prepareStatement("insert into dbPICTURE values
(?,?)");
// ***use as many ??? as you need to insert in the exact
order***
ps.setString(1,file.getName());
ps.setBinaryStream(2,fis,(int)file.length());
ps.close();
fis.close();
Is possible to open a connection to a database with
exclusive mode with JDBC?
I think you mean "lock a table in exclusive mode". You
cannot open a connection with exclusive mode. Depending
on your database engine, you can lock tables or rows in
exclusive mode.
In Oracle you would create a statement st and run
st.execute("lock table mytable in exclusive mode");
Then when you are finished with the table, execute the
commit to unlock the table. Mysql, Informix and
SQLServer all have a slightly different syntax for this
function, so you'll have to change it depending on your
database. But they can all be done with execute().
What are the standard isolation levels defined by JDBC?
The values are defined in the class java.sql.Connection
and are:
* TRANSACTION_NONE
* TRANSACTION_READ_COMMITTED
* TRANSACTION_READ_UNCOMMITTED
* TRANSACTION_REPEATABLE_READ
* TRANSACTION_SERIALIZABLE
Update fails without blank padding. Although a particular
row is present in the database for a given key,
executeUpdate() shows 0 rows updated and, in fact, the
table is not updated. If I pad the Key with spaces for
the column length (e.g. if the key column is 20 characters
long, and key is msgID, length 6, I pad it with 14
spaces), the update then works!!! Is there any solution
to this problem without padding?
In the SQL standard, CHAR is a fixed length data type.
In many DBMSes ( but not all), that means that for a
WHERE clause to match, every character must match,
including size and trailing blanks. As Alessandro
indicates, defining CHAR columns to be VARCHAR is the
most general answer.
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
|