JDBC Resources and Connection Pool : Explain

JDBC Resources A JDBC resource (data source) provides applications with a means of connecting to a database. Typically, the administrator creates a JDBC resource for each database accessed by the applications deployed in a domain. (However, more than one JDBC resource can be created for a database.)   JDBC Resources To store, organize, and retrieve [...]

60. What is the difference between TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE

You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that [...]

59. How to make updates to updatable result sets.

Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to [...]

58. How to Retrieve Warnings

SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or [...]

57. How can you load the driver.

Driver can be loaded in 2 ways : 1. class.forName(“sun.jdbc.odbc.JdbcOdbc”); 2. Driver d=new Driver(“sun.jdbc.odbc.JdbcOdbc”);    DriverManager.registerDriver(d); vendar specific one: Driver d=new oracle.driver.oracleDriver();

56. How can you retrieve data from the ResultSet

Example: Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SELECT COF_NAME, PRICE FROM COFFEES”); while (rs .next() ) { //Iam assuming there are 3 columns in the table. System.out.println ( rs.getString(1)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); } //don’t forget to close the resultset, statement & connection rs.close(); //First  stmt.close(); //Second con.close(); //Last  System.out.println(“You are done”); 

55. How do you implement Connection Pooling

Connection Pooling can be implemented by the following way.   A javax.sql.ConnectionPoolDataSource interface that serves as a resource manager connection factory for pooled java.sql.Connection objects. Each database vendors provide the implementation for that interface.  For example, the oracle vendors implementation is as follows: oracle.jdbc.pool.oracleConnectionPoolDataSource Class.  A javax.sql.PooledConnection interface encapsulates the physical connection for the database. Again, the [...]

54. How to call a stored procedure from JDBC

Stored Procedures can be called in java by using the prepareCall() method which returns a CallableStatement object. CallableStatement cs = con.prepareCall(“{call Procedure_name}”); ResultSet rs = cs.executeQuery();

53. What are the three statements in JDBC & difference between them.

1.Statement which is used to run simple sql statements like select and update 2. PrepareStatment is used to run Pre compiled sql.  3. CallableStatement is used to execute the stored procedures.

52. What is the difference between ResultSet and RowSet

A ResultSet maintains a connection to a database and because of that it can’t be serialized and also we cant pass the Resultset object from one class to other class across the network. RowSet is a disconnected, serializable version of a JDBC ResultSet and also the RowSet extends the ResultSet interface so it has all [...]

51. What is a transaction.

To emulate a business transaction, a program may need to perform several steps. A financial program, for example, might transfer funds from a checking account to a savings account with the steps listed in the following pseudocode: begin transaction debit checking account credit savings account update history log commit transaction Either all three of these [...]

50. What is the purpose of setAutoCommit()

Autocommit behavior    The JDBC specification requires that, by default, a COMMIT is performed after each data modification statement. Currently, the server-side JDBC behavior is to commit. You can control this behavior using a statement such as the following: conn.setAutoCommit( false ) ; where conn is the current connection object. Connection defaults    From server-side JDBC, only the first [...]

49. What is the difference between statement and prepared statment?

Prepared Statement is Pre-compiled class , but Statement is not. So in PreparedStatement the execution will be faster. Actually when u submit a simple statement to the databse, at first the DBMS parses it and sends it back with the result, so again when u send the same statement again the DBMS server parses it [...]

48. What is a savepoint.

Save point is a feature using which we can save  status of the transaction to a perticular extent.so that if anytime we have lost a transaction we can get it back using save point.

47. What is the difference between ResultSetMetaData and DatabaseMetaData

ResultSetMetaData You can interrogate JDBC for detailed information about a query’s result set using a ResultSetMetaData object. ResultSetMetaData is a class that is used to find information about the ResultSet returned from a executeQuery call. It contains information about the number of columns, the types of data they contain, the names of the columns, and [...]

46. What do you mean by batch update

The JDBC drivers that support JDBC 2.0 and above support batch updates. With batch updates, instead of updating rows of a  table one at a time, you can direct JDBC to execute a group of updates at the same time. Statements that can be included in the same batch of updates are known as batchable [...]

45. What is the difference between local and global transaction.

A transaction is atomic unit of Work.The tasks which are made into the transaction act as a unit which can be executed successfully all,or if at least one task fails to its promise ,then the effect of all the tasks are to be rollbacked.Thus transaction is committed or rolled backed. Transactions can be divided into [...]

44. What the new features in JDBC 2.0

The following are the JDBC 2.0 features. Resultset enhancements JDBC 2.0 supports scrollable resultset capability under three major headings, namely, forward-only, scroll-insensitive, and scroll-sensitive. Each of these resultsets can in turn be Read_only or Updatable. Forward_only/Read_only is feature of JDBC 1.0. Batch Updates automatic batch update and explicit batch update. Advanced Data Types The advanced [...]

43. Explain JDBC Driver Types

JDBC drivers are divided into four types or levels. Each type defines a JDBC driver implementation with increasingly higher levels of platform independence, performance, and deployment administration. The four types are: Type 1: JDBC-ODBC Bridge Type 2: Native-API/partly Java driver Type 3: Net-protocol/all-Java driver Type 4: Native-protocol/all-Java driver Type 1: JDBC-ODBC Bridge  The type 1 [...]

42. What is JDBC

JDBC (Java Database Connectivity) provides a standard interface for accessing a relational database from a Java application regardless of where the application is running and where the database is. It provides a way for Java applications to call SQL and PL/SQL. In other words it is a way to execute SQL statements and also call [...]

41. Explain Basic Steps in writing a Java program using JDBC

Basically a Java program implementing JDBC performs the following functions: Load a JDBC driver. Establish a database connection. Optionally interrogate the database for capability subset. Optionally retrieve schema metadata information. Construct a SQL or callable statement object and send queries or database tasks. Execute the database tasks or process resultsets. Close the statement object and [...]

Follow

Get every new post delivered to your Inbox.