Java interview question 11

Source: Internet
Author: User

. How does JDBC handle transactions? In a JavaBean database operation, a transaction is an inseparable unit of work consisting of one or more SQL statements updated to the database. The entire transaction can be committed to the database only when all operations in the transaction are completed normally. If one operation is not completed, the entire transaction must be canceled, this is the transaction Script Mode. We end the transaction operation by committing commit () or rolling back rollback. The transaction operation methods are located in the java. SQL. Connection interface. When you establish a connection to the database for the first time, the connection is in the automatic commit mode by default. You can call setAutoCommit (false) to disable automatic commit of transactions. Then, multiple SQL statements for updating the database can be used as a transaction. After all operations are completed, commit () is called for overall commit. If one of the SQL operations fails, the commit () method is not executed, but sqlexception is generated. In this case, you can capture the Exception Code block and call the rollback () method to cancel the transaction. 62. Write out several interfaces commonly used in Jdbc: Connection to a specific database (session ). Execute the SQL statement in the connection context and return the result. PreparedStatement: the object of the pre-compiled SQL statement. Statement: the object used to execute a static SQL Statement and return the result it generates. CallableStatement: The interface used to execute SQL stored procedures. ResultSet: indicates the data table of the database result set. It is usually generated by executing a statement to query the database. Sixty-three: your understanding of Statement, PreparedStatement, and CallableStatement. statement is used to execute a static SQL Statement, return the object of the result it generates, and determine the SQL statement during execution. PreparedStatement indicates the object of the pre-compiled SQL statement. SQL statements are pre-compiled and stored in the PreparedStatement object. This object can then be used to efficiently execute this statement multiple times. You can pass parameters to determine the SQL. CallableStatement interface used to execute the SQL stored procedure when obtaining the PreparedStatement object. If an output parameter needs to be registered, it indicates an output parameter. Steps for accessing the database in Java? 1) register the driver; 2) establish a connection; 3) create a Statement; 4) execute an SQL Statement; 5) process the result set (if the SQL Statement is a query Statement); 6) Close the connection. When PreparedStatement is created, an SQL statement is specified. It is usually used to execute SQL statements with the same structure multiple times.. Which class is used to execute the stored procedure? How do I operate the output parameters? (Operation) CallableStatement c = con. prepareCall ("{call getCustomerName (?,?)} "); C. setString (1, "1"); c. registerOutParameter (2, java. SQL. types. VARCHAR); c.exe cute (); c. getString (2); Sixty-six, Class. what is the role of forName? Why? JVM is required to search for and load the specified class. The most familiar thing is to load the driver class when connecting to the database through JDBC. Register a database driver and load the driver to the current JVM. 17th. What is Jdo? JDO is a new specification for Java object persistence. It is short for java data object and is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage. Therefore, for developers, no additional code (such as the use of JDBC APIs) is required to store data objects ). These tedious routine work has been transferred to the JDO product provider, freeing developers to concentrate their time and effort on business logic. In addition, JDO is flexible because it can run on any data underlying layer. JDBC is more common for Relational Database Service (RDBMS) JDO and provides underlying storage functions for any data, such as relational databases, files, XML, and object databases (ODBMS, makes applications more portable. (O/rMapping tool set processing ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.