Professional Documents
Culture Documents
com/group/jiny JINY
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
parameters
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]
jdbc:odbc:jiny
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?
1.INSERT
2.DELETE
3.TRUNCATE
4.UPDATE
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 ?
Statement
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
context.
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.
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
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
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.
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
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
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..
An alternative is to use system-generated artificial primary key values. These are often called surrogate keys because
they are replacements for the intelligent keys, or blind keys because the user doesn't see them.
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
22. How will you copy the structure of a table without copying the data?
create table <new_tname> as select * from <existing_tname> where 1 = 0; (or any invaid condition)
23. How to find out the database name from SQL*PLUS command prompt?
select name from v$database;
--> translate translates "single character at a time" like nth character in the match set(second parameter) with nth
character in the replacement set (third parameter)
translate(String, match_set, replacement_set)
eg : translate('abcabccab', 'abc', 'def') = defdeffde
31. When do you get contraint violtaion? What are the types of constraints?
Primary Key Constraint, Refererntial Constraint, Unique Constraint, not null constraint, Check.
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
---> refer normaliztion materials
36. Why can a "group by" or "order by" clause be expensive to process?
--> Involves I/O operation i.e, Makes use of memory from Temporary segment. Other I/O related processes are made
to wait.
42. What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a
table.
Drop --> deletes the entire table & all views, synonyms created become INVALID; grants given also become
invalid;
Truncate --> deletes the contents of the table; Commits automatically. highwater mark is reset.
delete all records --> deletes the contents of the table; Doesn't commit automatically. highwater mark is remains at
the same place.
http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
OR
CREATE [SHARED][PUBLIC] DATABASE LINK <link_name>
[CONNECT TO <user> IDENTIFIED BY <password>]
[AUTHENTICATED BY <user> IDENTIFIED BY <password>]
[USING <connect_string>]
45. whts the diff betn char and varchar in any database?
http://groups.yahoo.com/group/jiny JINY