First, find out the problems in the function. The following topics are completed in the LAB05 project.
1. Please add a comment to the class and each method in Mysqlconnbean.java
2, package org.easybooks.bookstore.jdbc;
3.
4, import java.sql.*;
5.
6. public class Mysqlconnbean {
7, private Statement stmt=null;
8, private Connection conn=null;
9, private ResultSet rs=null;
10.
11.
12, public void Openconn () throws Exception {//Connection database
13, Class. forname ("Com.mysql.jdbc.Driver");
14, String url= "Jdbc:mysql://localhost:3306/test";
15, String user= "root";
16, String password= "123456";
17, Conn=drivermanager. getconnection (URL, user, password);
18,}
19.
20.
21. Public ResultSet ExecQuery (String sql) {///execute SQL statement
22, rs=null;
23. Try{
24, Stmt=conn.createstatement (ResultSet. Type_scroll_sensitive, ResultSet. concur_read_only);
25, Rs=stmt.executequery (SQL);
26,}catch (SQLException e) {
27, System. err. println ("Data.executequery:" +e.getmessage ());
28,}
29.
30, return rs;
31,}
32.
33. public void closestmt () {//Close statement Object
34. Try{
35, Stmt.close ();
36,}catch(SQLException e) {
37, System. err. println ("Data.executequery:" +e.getmessage ());
38,}
39,}
40.
41. public void Closeconn () {//Close database Connection object
42. Try{
43, Conn.close ();
44,}catch(SQLException e) {
45, System. err. println ("Data.executequery:" +e.getmessage ());
46,}
47,}
48,}
49.
50, find out the defects in the project, and give solutions (at least 3, do not include the following example).
Note: The flaws mentioned here are not necessarily errors, but areas where improvements are obvious.
Such as: Can not enter the password unlimited, easy to be brute force, there is a security risk.
Solution: Password entered 3 times error, close the browser. It is best to add a verification code.
BUG: Users can log in directly to the welcome.jsp page.
Solution: Set the user name to the session property to verify that the user's SessionID is empty.
BUG: Error page did not do any processing
Solution: Set the appropriate processing for the error page and jump back to the login page.
Defect: No validation of NULL input data
Solution: Increase the operation of empty input data
Second, please follow the requirements of the following Java code test. The function of the code is to look for an element with a value of key in an array of elements in ascending order using binary lookup.
(1) The basic path method is required to give the program control flow graph;
(2) Calculate loop complexity
16-14+2=4
(3) Give all the independent paths, and the corresponding test cases and expected results
Path 1:1-2-3-13-14
Test case: Satisfies Low>hign's use case (array[]=3,2,1 Key=1) Expected Result: will jump out while statement
Path 2:1-2-3-4-5-6-7-12-13-14
Test case: Satisfies Key==array[mid] use case (array[]=1,2,3 key=2) Expected Result: will execute 5.6
Path 3:1-2-3-4-5-8-9-12-13-14
Test case: Satisfying Key<array[mid] use case (array[]=1,2,3 Key=1) Expected Result: will jump out of 8.9 statements
Path 4:1-2-3-4-5-10-11-12-13-14
Test case: Satisfying Key>array[mid] use case (array[]=1,2,3 key=2) Expected Result: will jump out of 10.11 statements
Fifth time Assignment