JSP enterprise interview questions (5)

Source: Internet
Author: User

JSP enterprise interview questions (5)
7-2 illustrates how JDBC works and lists common objects. (Enterprise pen exam)

Establishing a connection is to establish a connection with the database, that is, to create a connection instance. The getconnection () method of the drivermanager class will establish a database connection:

The statement object is used to send SQL statements to the database. Three statement objects exist: (1) statement; (2) preparedstatement (inherited from statement); (3) callablestatement (inherited from preparedstatement ).

The resultset contains all rows that conform to the SQL statement execution results, and provides access to the data in these rows through a set of get methods.

7-3 7-16, requirement: search for "Zhang San", select the names of all courses, and write SQL statements. (Enterprise pen exam)

Select C. cname from SC a, student B, course C

Where a. CNO = C. CNO

And a. Sno = B. SnO and B. sname = 'zhang san'

Are the code segments below 7-4 correct? Please note. (Enterprise pen exam)

Pst = conn. preparestatement ("insert into grade (student ID) values (?) ");

For (INT I = 101; I <111; I ++ ){

Pst. setint (1, I );

Pst. addbatch ();

}

Pst.exe cute ();

}

 

Error: pst.exe cutebatch ();

7-5 briefly describe the basic concepts of transactions. How to Implement transactions in JDBC?

A transaction is a collection of events. Executing an SQL statement can be understood as an event. The transaction contains multiple events. If each event can be successfully executed, the transaction will be executed. If any event cannot be successfully executed, other events of the transaction will not be executed.

Boolean defacomcommit = conn. getautocommit ();

Conn. setautocommit (false );

Try {

Stmt.exe cuteupdate (strsql1 );

Stmt.exe cuteupdate (strsql2 );

Conn. Commit ();

}

Catch (exception e ){

Conn. rollback ();

E. printstacktrace ();

}

Finally {

If (stmt! = NULL ){

Stmt. Close ();

}

If (Conn! = NULL ){

Conn. Close ();

}

}

Conn. setautocommit (defaultcommit );

The 7-6 result set type and result set concurrency have different situations. What is the function.

Determines whether the resultset object created by this statement object can be rolled, and whether the result set is sensitive to changes in the database. The Int constant in the resultset class is used to represent the result set type. There are three types of result set types:

L resultset. type_forword_only: specifies that the resultset object cannot be rolled, which is the default value.

L resultset. type_scoll_insensitive: specifies that the resultset object can be rolled, but it is not sensitive to changes in the database.

L resultset. type_scoll_sensitive: specifies that the resultset object can be rolled and is sensitive to database modification.

The concurrency of the result set determines whether the resultset object can modify rows in the database. You can use the int constant defined in the resultset class to specify the concurrency of the result set.

L resultset. concur_read_only, specifies that the resultset object cannot modify the database. The default value is.

Resultset. concur_updatable, specifies that the resultset object can modify the database.

 

Related Article

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.