What is the difference between the statement.executequery and statement.executeupdate java statement




















Explain JDBC statement. What are the steps to connect to the database in JDBC? What are the types of JDBC statements? Which JDBC interface is responsible for managing transactions? How many layers are there in JDBC architecture? What are the design patterns involved in JDBC architecture?

Is the connection pool object thread safe? How do you execute stored procedures and functions using JDBC? What is row prefetching in JDBC? What is the return type of Class. How do you create your own transactions in JDBC?

List few good practices in JDBC. What are the isolation levels defined by JDBC? How can we store images in the database using JDBC? Explain JDBC batch processing and its benefits. What are the locking systems in JDBC? Which data type do you prefer: byte array or a java. Blob in JDBC? Recently added About Javapedia. This method is meant to be used for select queries which fetch some data from the database. This method returns one java.

ResultSet object which contains the data returned by the query. This method is used for SQL statements which update the database in some way. This method returns an int value which represents the number of rows affected by the query. This value will be 0 for the statements which return nothing. This method can be used for all types of SQL statements. This method returns a boolean value. This method can be used by one thread to cancel a statement that is being executed by another thread.

The warning chain is automatically cleared each time a statement is re executed. This method may not be called on a closed Statement object; doing so will cause an SQLException to be thrown. Note: If you are processing a ResultSet object, any warnings associated with reads on that ResultSet object will be chained on it rather than on the Statement object that produced it.

After a call to this method, the method getWarnings will return null until a new warning is reported for this Statement object. This name can then be used in SQL positioned update or delete statements to identify the current row in the ResultSet object generated by this statement. Note: By definition, the execution of positioned updates and deletes must be done by a different Statement object than the one that generated the ResultSet object being used for positioning.

Also, cursor names must be unique within a connection. Normally you can ignore this unless you are 1 executing a stored procedure that you know may return multiple results or 2 you are dynamically executing an unknown SQL string. The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result s. This method should be called only once per result.

Returns: the current result as a ResultSet object or null if the result is an update count or there are no more results Throws: SQLException - if a database access error occurs or this method is called on a closed Statement See Also: execute java.

Returns: the current result as an update count; -1 if the current result is a ResultSet object or there are no more results Throws: SQLException - if a database access error occurs or this method is called on a closed Statement See Also: execute java.

The default value is ResultSet. Note that this method sets the default fetch direction for result sets generated by this Statement object. Each result set has its own methods for getting and setting its own fetch direction. Parameters: direction - the initial direction for processing rows Throws: SQLException - if a database access error occurs, this method is called on a closed Statement or the given direction is not one of ResultSet.

If this Statement object has not set a fetch direction by calling the method setFetchDirection , the return value is implementation-specific. Returns: the default fetch direction for result sets generated from this Statement object Throws: SQLException - if a database access error occurs or this method is called on a closed Statement Since: 1. If the value specified is zero, then the hint is ignored.

The default value is zero. If this Statement object has not set a fetch size by calling the method setFetchSize , the return value is implementation-specific. Returns: the default fetch size for result sets generated from this Statement object Throws: SQLException - if a database access error occurs or this method is called on a closed Statement Since: 1.

Returns: either ResultSet. Returns: one of ResultSet. The commands in this list can be executed as a batch by calling the method executeBatch. Throws: SQLException - if a database access error occurs, this method is called on a closed Statement or the driver does not support batch updates Since: 1.

String , DatabaseMetaData. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands.

If the driver continues processing after a failure, the array returned by the method BatchUpdateException.

Returns: an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch. Throws: SQLException - if a database access error occurs, this method is called on a closed Statement or the driver does not support batch statements.

Throws BatchUpdateException a subclass of SQLException if one of the commands sent to the database fails to execute properly or attempts to return a result set.

SQLTimeoutException - when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement Since: 1.

Returns: the connection that produced this statement Throws: SQLException - if a database access error occurs or this method is called on a closed Statement Since: 1. If this Statement object did not generate any keys, an empty ResultSet object is returned. Note: If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys. This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available.

This array contains the names of the columns in the target table that contain the auto-generated keys that should be made available. Parameters: sql - any SQL statement autoGeneratedKeys - a constant indicating whether auto-generated keys should be made available for retrieval using the method getGeneratedKeys ; one of the following constants: Statement.



0コメント

  • 1000 / 1000