Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
!JDBC Oracle Questions

!JDBC Oracle Questions

Ratings: (0)|Views: 62|Likes:
Published by api-3694132

More info:

Published by: api-3694132 on Oct 14, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





1. What is the advantage of using a PreparedStatement?

For SQL statements that are executed repeatedly, using a PreparedStatement object would almost always be faster
than using a Statement object. This is because creating a PreparedStatement object by explicitly giving the SQL
statement causes the statement to be precompiled within the database immediately. Thus, when the
PreparedStatement is later executed, the DBMS does not have to recompile the SQL statement and prepared an
execution plan - it simply runs the statement. Typically, PreparedStatement objects are used for SQL statements that
take parameters. However, they can also be used with repeatedly executed SQL statements that do not accept

2. What is a database URL?

A database URL (or JDBC URL) is a platform independent way of adressing a database. A database/JDBC URL is of
the form jdbc:[subprotocol]:[node]/[databaseName]

3. ResultSet?

Resultset donot contain the data ie the rows returned by executing a query.It Contains a cursor through which we can
retrieve the data. Initally it points to a position immediately preceeding the first row.Every time we call its next() method
the cursor move to the next row.Thus we retrieve a single row by calling resultset's next()
method.Generally the application Server will try its maximum to handle any abnormal exceptions that might crash the
server.But i never faced such a problem practically.Can you please explain me the circumstances when a server might
carsh and when a System can crash?

4. two types of sub query: correlated and non-correlated

Correlated Sub query is a sub query that is evaluated once for each row processed by the parent statement. Parent
statements can be Select, Update or Delete. Non-correlated sub queries are executed once for the whole

this one is to find 6th highest salary in emp table.
WHERE A.sal > B.sal )

5. Which one of the following cannnot be Rollbacked in Oracle

TRUNCATE Cannot be Rollbacked !

6. When i want to get the values from a vector and put in a database which statement is optimized one ?

Prepared Statement
Callable Stmt

ALL of the Above

Prepared statement is the ans. Callable statements are used for stored procedure invocations. If you use callable
statements, it will obviously be fast, but all the processing logic will be shifted on to the database. Your java code or
statement will as such do nothing. So first of all, callable statements cannot be compared with other statements in this

7. What is thin driver ,how do u identify it ?
Oracle has Thin Driver and OCI Driver. Those are 2 different drivers. Those are the names of the drivers.
8. while connecting to database via JDBC,is bridge is always needed?

One need not use JDBC-ODBC bridge Driver to connect to database.In fact this type of driver should be avoided for
performance reasons. Use type 2 or type 4
driver.If the database id MS access u have no option but to go for this bridge.

9. Which method in the sql package is used for all opertions (only one method should be used) Which
perfoms ... Viz ., INSERT,UPDATE,DELETE,SELECT Etc.,
What is the disadvantage of that method

suppose statement.execute() will take any DDL or DML statements. but this method is primarily used to execute
statements that could be created on the fly i mea n dynamically
10. What is the difference between a trigger and a stored procedure?
Trigger is executed implicity when an event occurs such as row inserted, updated or deleted. Stored procedure on the
other hand has to be called explicitly.
11.What type of situations we go for Statement instead of Preapared Statement
Where we can use Statement
Prepared Statements are not always fast !

Lets go back to the roots. Lets call Statement as S and Prepared statement as PS. How is a query executed in java ?
establish a connection, create statement, execute query. First step, getting a connection is same for both S and PL.
Second step is similar to S and PS, if not same. Only difference, different objects are instantiated. Third and the most
important + deciding step, Execute.

In case of S,
1 query is passed on to the database
2 database will now parse the query
3 database prepares a execution plan
4 database executes execution plan and creates a cursor
5 database throws back a cursor pointer, pointing to the first row.

In case of PS
1 query is passed on to the database
1A Database will search for execution plan for this query
2 If execution plan doesnot exist, database will now parse the query
3 If execution plan doesnot exist, database prepares a execution plan
3B Database stores execution plan for future reference.
4 database executes execution plan and creates a cursor
5 database throws back a cursor pointer, pointing to the first row.

In case of S, there will always be 5 steps.
In case of SP, there will be 2 extra steps, the very first time. Also, some server (resources) memory will be consumed
to keep the plan active. This "may" make the server heavy. So finally it is Speed over Memory. There should be a
compromise in between.

This is the compromise. In case of "simple" queries(insert and updates are generally simple), execution plans are
preety straight forward.. Also in case of simple select.
Prepared statements makes sense only when we have repititive and/or complex database queries! For rest, simple
queries should do the work. Remember, Server resources are costly. Because a small increase in server time, will be
propogeted to all connected users. So if we use all Prepared statements, we simply make the server heavy, and in turn
decrease the response time. So finally PS didnt made sense.
This is the reason why, S, PS and SP's should be used smartly. For usual database operations, S are ok..
12. Surrogate Key?
When business-related columns are used as primary keys they are often calledintelligent or natural keys.
An alternative is to use system-generated artificial primary key values. These are often calledsurrogate keys because
they are replacements for the intelligent keys, or blind keys because the user doesn't see them.
13. The difference between VARCHAR and VARCHAR2?

VARCHAR was the earlier datatype and which was obseleted by VARCHAR2.VARCHAR2 allocates the memory dynamically as opposed to VARCHAR. I believe VARCHAR2 started from Oracle 8i, but not sure if it was in earlier versions too.

14. Oracle DB is known as ORDBMS? Why?
Oracle 8i onwards supports Object types.
15. Whats Client side cursor and server side cursor?

Client side cursors are place holders for the query results returned to the client program. E.g. all select queries returns client side cursor to the program like ResultSet in java. May be Server side cursor deals with stored procedures on the database side.. not sure.

16. Difference between Delete/truncate/drop table.
Delete actually deletes the individual row in the table. In this process it copies data into roll back segements for the
transaction purpose.

Delete needs commit, truncate does not need a commit
Delete dml, truncate is ddl statement
Delete does not reset the water mark, truncate resets the water mark
Delete u can use WHERE clause ,where in Truncate u can not,
Truncate is faster and consumes less memory ..
A transaction Log is entered when , Delete is used for Truncate no Transaction Log
Truncate cannot activate a Trigger , since it is not logged in the transaction
Truncate cannot be used by a table where refernced by foreign key constratint
Truncate cannot be used in table involving indexed view.

Drop with totally delete the table itself.
17. What is a view?
It is a logical grouping of relational tables. The advantage of view is that the query is precompiled and provides an
abstraction to the client program. ORACLE 8i onwards support object views.
18. What are the different types of joins?
---> Self-Join, Outer Join, Inner Join
19. What cursor type do you use to retrieve multiple recordsets?
--> Explicit Cursor.
Note : To retrieve Singe record we use Implicit Cursor
20. Diffrence between a "where" clause and a "having" clause
--> 'Where & having' clauses Filter the record based on some condition, but having clause can be used only with a
Group by

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->