[READ: Why-JAVA][Start-Learning-JAVA][Why-Java's-Hot][Start-Using-LINUX][Java-Q-&-A][Question][Java-SE-6-Doc][Struts-Doc][Java-Tutorial-Index] [Java-Certification]
[Tech.][Struts.][Servlet.][JSP.][EJB.][JNDI-JMS][SQL.][JDBC.]
CORE-JAVA: [OOP][CLASS][ABSTRACT][EXCEPTIONS][THREADS][UTILS][PACKAGES][JVM][CASTING][NETWORKING][RMI-XML]
[Tech.][Struts.][Servlet.][JSP.][EJB.][JNDI-JMS][SQL.][JDBC.]
CORE-JAVA: [OOP][CLASS][ABSTRACT][EXCEPTIONS][THREADS][UTILS][PACKAGES][JVM][CASTING][NETWORKING][RMI-XML]
What are stored procedures? How are they useful? (JDBC)
A stored procedure is a set of statements/commands which resides in the database. The stored procedure is a pre-compiled code which saves database effort, of parsing and compiling sql statements every time a query is run. Each Database has it’s own stored procedure language, usually a variant of C with a SQL pre-processor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/house-keeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.
What Class.forName will do while loading drivers? (JDBC)
It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
Given two tables Student(SID, Name, Course) and Level(SID, level) write the SQL statement to get the name and SID of the student who are taking course = 3 and at freshman level. (JDBC)
SELECT Student.name, Student.SID
FROM Student, Level
WHERE Student.SID = Level.SID
AND Level.Level = "freshman"
AND Student.Course = 3;
What is the query used to display all tables names in SQL Server (Query analyzer)? (JDBC)
select * from information_schema.tables
How many types of JDBC Drivers are present and what are they? (JDBC)
There are 4 types of JDBC Drivers
Type 1: JDBC-ODBC Bridge Driver
Type 2: Native API Partly Java Driver
Type 3: Network protocol Driver
Type 4: JDBC Net pure Java Driver
What is the fastest type of JDBC driver? (JDBC)
JDBC driver performance will depend on a number of issues:
(a) the quality of the driver code,
(b) the size of the driver code,
(c) the database server and its load,
(d) network topology,
(e) the number of times your request is translated to a different API.
In general, all things being equal, you can assume that the more your request and response change hands, the slower it will be. This means that Type 1 and Type 3 drivers will be slower than Type 2 drivers (the database calls are make at least three translations versus two), and Type 4 drivers are the fastest (only one translation).
Is the JDBC-ODBC Bridge multi-threaded? (JDBC)
No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading.
Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection? (JDBC)
No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.
What is cold backup, hot backup and warm backup recovery? (JDBC)
a. cold backup - All these files must be backed up at the same time, before the database is restarted.
b. hot backup - official name is 'online backup' ? is a backup taken of each table-space while the database is running and is being accessed by the users.
When we will De-normalize data? (JDBC)
Data de-normalization is reverse procedure, carried out purely for reasons of improving performance.It maybe efficient for a high-throughput system to replicate data for certain data.
What is the advantage of using Prepared-Statement? (JDBC)
If we are using Prepared-Statement the execution time will be less.The PreparedStatement object contains not just an SQL statement,but the SQL statement that has been pre-compiled.This means that when the PreparedStatement is executed,the RDBMS can just run the PreparedStatement's Sql statement without having to compile it first.
What is a "dirty read"? (JDBC)
Quite often in database processing, we come across the situation wherein one transaction can change a value, and a second transaction can read this value before the original change has been committed or rolled back. This is known as a dirty read scenario because there is always the possibility that the first transaction may rollback the change, resulting in the second transaction having read an invalid value. While you can easily command a database to disallow dirty reads, this usually degrades the performance of your application due to the increased locking overhead. Disallowing dirty reads also leads to decreased system concurrency.
What is Metadata and why should I use it? (JDBC)
Metadata ('data about data') is information about one of two things: Database information (java.sql.DatabaseMetaData), or Information about a specific ResultSet (java.sql.ResultSetMetaData).
Use DatabaseMetaData to find information about your database, such as its capabilities and structure. Use ResultSetMetaData to find information about the results of an SQL query, such as size and types of columns
Different types of Transaction Isolation Levels? (JDBC)
The isolation level describes the degree to which the data being updated is visible to other transactions. This is important when two transactions are trying to read the same row of a table. Imagine two transactions A & B.
Three types of inconsistencies can occur:
· Dirty-read: A has changed a row, but has not committed the changes. B reads the uncommitted data but his view of the data may be wrong if A rolls back his changes and updates his own changes to the database.
· Non-repeatable read: B performs a read, but A modifies or deletes that data later. If B reads the same row again, he will get different data.
· Phantoms: A does a query on a set of rows to perform an operation. B modifies the table such that a query of A would have given a different result. The table may be inconsistent.
TRANSACTION_READ_UNCOMMITTED : DIRTY READS, NON-REPEATABLE READ AND PHANTOMS CAN OCCUR.
TRANSACTION_READ_COMMITTED : DIRTY READS ARE PREVENTED, NON-REPEATABLE READ AND PHANTOMS CAN OCCUR.
TRANSACTION_REPEATABLE_READ : DIRTY READS , NON-REPEATABLE READ ARE PREVENTED AND PHANTOMS CAN OCCUR.
TRANSACTION_SERIALIZABLE : DIRTY READS, NON-REPEATABLE READ AND PHANTOMS ARE PREVENTED.
What is 2 phase commit? (JDBC)
A 2-phase commit is an algorithm used to ensure the integrity of a committing transaction In Phase 1, the transaction coordinator contacts potential participants in the transaction. The participants all agree to make the results of the transaction permanent but do not do so immediately. The participants log information to disk to ensure they can complete Phase 2. If all the participants agree to commit, the coordinator logs that agreement and the outcome is decided. The recording of this agreement in the log ends Phase
In Phase 2, the coordinator informs each participant of the decision, and they permanently update their resources.
How do you handle your own transaction ? (JDBC)
Connection Object has a method called setAutocommit ( Boolean istrue)
- Default is true
Set the Parameter to false , and begin your transaction
What is the normal procedure followed by a java client to access the db.? (JDBC)
The database connection is created in 3 steps:
1.Find a proper database URL (see FAQ on JDBC URL)
2.Load the database driver
3.Ask the Java DriverManager class to open a connection to your database
In java code, the steps are realized in code as follows:
1.Create a properly formatted JDBR URL for your database. (See FAQ on JDBC URL for more information). A JDBC URL has the form
jdbc:someSubProtocol://myDatabaseServer/theDatabaseName 2. Class.forName("my.database.driver");
3 . Connection conn = DriverManager.getConnection("a.JDBC.URL", "databaseLogin","databasePassword");
What is a data source? (JDBC)
A DataSource class brings another level of abstraction than directly using a connection object. Data source can be referenced by JNDI. Data Source may point to RDBMS, file System , any DBMS etc.
What are collection pools? What are the advantages? (JDBC)
A connection pool is a cache of database connections that is maintained in memory, so that the connections may be reused
How to call a Stored Procedure from JDBC? (JDBC)
The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure.
E.g.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
How do you get Column names only for a table (SQL Server)? Write the Query. (JDBC)
select name from syscolumns where id=(select id from sysobjects where name='user_hdr') order by colid --user_hdr is the table name
What are the steps in the JDBC connection?
A: While making a JDBC connection we go through the following steps : Step 1 : Register the database driver by using : Class.forName(\" driver classs for that specific database\" ); Step 2 : Now create a database connection using : Connection con = DriverManager.getConnection(url,username,password); Step 3: Now Create a query using : Statement stmt = Connection.Statement(\"select * from TABLE NAME\"); Step 4 : Exceute the query : stmt.exceuteUpdate();
Java - Encaptulation - Local Class - Anonymous Class
*Lesson 1 What is encapsulation? *Lesson 2 What is a local class? *Lesson 3 What is an anonymous class?
Java Q and Ans (CORE JAVA, THREADS, JAVA UTILS, DESIGN PATTERN, JSP, SERVLET, EJB, JNDI, JMS, RMI, JDBC, XML)
There are 719 questions in Java with 248 comments (JDBC) *Java interview Q and Ans *Only Questions *Confuseing
"WE" has More Power than "I". Please leave a comment if you encounter any problems or have any suggestions.
The-Bitter-Truth.
Duty-Responsibility-Law-and-Order. "Happy-Kingdom"-proudly-proclaimed-as-"Paradise" Trying-to-learn-something-for-the-first-time. Time-is-the-only-solution. For-every-Action-There-is-an-Equal-and-Opposite-Reaction. Logic-of-Good-and-Bad. Duties-Responsibilities-verses-Luxuries-and-Pleasures. Beggars!