Java face Test-javaweb Chapter seven __HTML5

Source: Internet
Author: User
Tags connection pooling rollback sql injection sql injection attack first row
Java Face Test-javaweb Chapter seven

61,JDBC the basic steps to access a database.
1, load Driver
2, get the connection object through the DriverManager object connection
3, getting the session through the Connection object
4, through the session of data additions and deletions to check, packaging objects
5, close the resource


62, tell me the difference between preparedstatement and statement.
1, efficiency: precompiled session than normal session object, the database system will not be the same SQL statement will not compile again
2, security: can effectively avoid SQL injection attacks. SQL injection attack is to input some illegal special characters from the client, so that the server side can still construct the SQL statement correctly, thus collecting the information and data of the program and server.
For example: "SELECT * from t_user where userName = '" + userName + "' and password = '" + Password + ""
If the username and password are entered as ' 1 ' or ' 1 ' = ' 1 '; The SQL statement for the production is:
"SELECT * from t_user where userName = ' 1 ' or ' 1 ' = ' 1 ' and password = ' 1 ' or ' 1 ' = ' 1 '" The where part of the statement does not act on the data filtering.


63, talking about the concept of a transaction, the steps of dealing with a transaction in JDBC programming.
A 1 transaction is a series of operations performed as a single logical unit of work.
2, a logical unit of work must have four properties, called atomicity, consistency, isolation, and persistence (ACID) attributes, that are the only way to become a transaction
Transaction processing steps:
3,conn.setautocomit (false); Set Submission as manual submission
4,conn.commit () COMMIT Transaction
5, the occurrence of abnormal, rollback conn.rollback ();


64, the principle of database connection pool. Why to use connection pooling.
1, database connection is a time-consuming operation, the connection pool allows multiple operations to share a connection.
2, the basic idea of database connection pool is to establish a "buffer pool" for database connection. Put a certain number of connections in the buffer pool beforehand, and when you need to establish a database connection, simply remove one from the buffer pool, and then put it back when you have finished using it. We can prevent the system from endlessly connecting to the database by setting the maximum number of connections to the connection pool. More importantly, we can monitor the number and usage of database connections through the connection pool management mechanism, and provide the basis for system development, testing and performance adjustment.
3, connection pooling is used to improve the management of database connection resources


What is 65,jdbc's dirty reading? What kind of database isolation level prevents dirty reads.

When we use transactions, it is possible that a row of data has just been updated while another query has read the newly updated value. This results in dirty reading because the updated data is not persisted, and the business that updates the row of data may be rolled back so that the data is invalid. The transactionreadcommitted,transactionrepeatableread of the database, and the Transaction_serializable isolation level can prevent dirty reads.


66, what is phantom reading and which isolation level can prevent phantom reading.

Phantom reading refers to a transaction that performs a single query that returns a different value. Suppose a transaction is querying data based on a condition, and then another transaction inserts a row of data that satisfies the query condition. The transaction then executes the query again, and the returned result set contains the new data that was just inserted. This line of new data is called a phantom line, and this phenomenon is called Phantom reading.

Only the Transaction_serializable isolation level can prevent phantom reads from being generated.


67,JDBC's DriverManager is used to do something.
JDBC's DriverManager is a factory class that we use to create a database connection. When the driver class of JDBC is loaded in, it registers itself into the DriverManager class
Then we will pass the database configuration information into the Drivermanager.getconnection () method, DriverManager will use the driver registered to it to get the database connection and return to the calling program.


What is the difference between the 68,execute,executequery,executeupdate.
The 1,statement execute (String query) method executes any SQL query, and returns true if the result of the query is a resultset. If the result is not resultset, such as INSERT or update query, it returns FALSE. We can get the resultset by its Getresultset method or by Getupdatecount () method to get the updated number of record bars.
The 2,statement executequery (String query) interface is used to execute a select query and return resultset. ResultSet is not null even if the query does not return a record. We usually use ExecuteQuery to execute the query, so that if the INSERT or UPDATE statement is passed in, it throws the error message "ExecuteQuery method can is not is used for update" of Java.util.SQLException. ,
3,statement's executeupdate (String query) method is used to execute insert or update/delete (DML) statements, or nothing to return, and for DDL statements The return value is of type int, if it is a DML statement , it is the number of updated bars, if it is DDL, return 0.
You should use the Execute () method only if you are unsure of the statement, or you should use the ExecuteQuery or Executeupdate method.


69,sql query out the results of pagination show how to do generally.

Oracle:

SELECT * FROM
(select *,rownum as tempid from student) t
where t.tempid between "+ pagesize* (pageNumber-1) +" and "+ Pagesize*pagenumber

Mysql:
SELECT * FROM students limit "+ pagesize* (pageNumber-1) +", "+ pageSize;

SQL Server:
Select Top "+ pageSize +" * FROM students where ID is not in +
(select Top + pageSize * (pageNumber-1) + IDs from students order by ID) +
"Order by ID;


What is the resultset of 70,JDBC.
After querying the database, it returns a ResultSet, which is like a datasheet for the query result set.
The ResultSet object maintains a cursor that points to the current data row. At the beginning, this cursor is pointing to the first row. If the next () method cursor that called ResultSet is moved down one line, the next () method returns False if there is no more data. You can use it in a for loop to traverse a dataset.
The default resultset is not updatable and the cursor can only be moved down. That means you can only traverse it from the first line to the last line. However, you can also create resultset that can be rolled back or updatable

The ResultSet object also closes automatically when the statement object that generates the resultset is closed or rerun, or the next resultset is fetched.
You can get the column data by resultset The getter method, passing in the column name or the ordinal number starting at 1.


Java Companion public number of major companies to organize a number of commonly used interview pen questions, for everyone in the spare time to learn some of the topics, accumulated over time, wait for the interview, everything is ripe, the interview will naturally be easier.

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.