1. Study summary 1.1 This week summarize your database-related content in the way you like (mind mapping or other).
2. Using database technology your system 2.1 briefly describes how to use the database to transform your system. What table do you want to build? The design of your watch.
A: Set up two DAO interfaces, respectively, for managing user modules and library modules, in which a book table is books used to store all the books in the library, and then a user table is created to users hold the user, and each user has a borrowing table with a table name with a letter in front of the user ID. a(the table name cannot be all numbers).
booksTable:
usersTable:
借阅表:
What are the key classes used in JDBC in the 2.2 system?
- 1.DriverManager class: For managing all drivers in a database
- 2.Connection interface: For connection to a specific database
- 3.PreparedStatement interface: For dynamic execution of SQL statements
- 4.ResultSet interface: a result set for temporary storage of database query operations
2.3 Key code for database related modules. Critical lines need to be annotated.
2.6 Select: Use Transaction Transformation system
PS: These two days is really too busy, so there are some bugs in the program has not changed, and so on back up.
3. Code volume Statistics 3.1 Statistics the amount of code completed this week
The weekly code statistics need to be fused into a single table.
| Week Time |
Total code Amount |
New Code Volume |
total number of files |
number of new files |
| 2 |
607 |
607 |
15 |
15 |
| 3 |
1642 |
1035 |
33 |
18 |
| 5 |
2044 |
402 |
42 |
9 |
| 6 |
2874 |
830 |
57 |
15 |
| 7 |
3161 |
287 |
63 |
6 |
| 8 |
4299 |
1138 |
72 |
9 |
| 9 |
4831 |
532 |
81 |
9 |
| 10 |
5475 |
644 |
93 |
12 |
| 11 |
5958 |
483 |
102 |
9 |
| 12 |
6819 |
861 |
116 |
14 |
| 13 |
7408 |
48X |
127 |
11 |
| 14 |
8348 |
940 |
141 |
14 |
| 15 |
9296 |
948 |
156 |
15 |
Option: 4. Database Learning Guide 1. MySQL Database basic operations
Create a database and insert your name and school number as a record. (, need to have their own school number, name)
Execute common SQL statements on your own established database (do it yourself, not necessary)
2. Use the statement operation database with the JDBC Connection database and Statement2.1. CompleteExperimental Task Book-topic 2。 One of thepublic static void displayAll()Andpublic static int insert(Student stu)Key code and show your own number.
2.2 If you want to finish querying student data based on a given name, complete the functionpublic Student findStuByName(String name), where is the SQL statement written?
2.3 What do you think is the routine of using JDBC to manipulate databases?
- 1. Load the database driver
- 2. Establishing a connection to the database
- 3. Create an Action object for the database
- 4. Defining an operation's SQL statement
- 5. Perform the operation of the database
- 6. Get and manipulate result sets
3. PreparedStatement and parameterized Query 3.1 using PreparedStatement, writepublic Student findStuByName(String name), the implementation is searched according to name. (Paste the key code and run, need to appear in the operation of the number, comparison of 2.2, indicating the difference between the two implementations)
A: PreparedStatement The main difference between using an object and using an Statement object is that it takes a ”?” placeholder for a parameterized query that allows the connection.preparedStatement(strSql) database to precompile its statements so that the statement can be strSql reused in subsequent queries. The superiority in speed is greater than Statement the query speed of the object.
3.2 If you want to implement Fuzzy Lookup, how to modify? such as writingpublic List findStusByName(String name), you can make a fuzzy match by name, such as including the namezhangStudents to find out.
Insert some related data first:
findStusByNameMethod:
Test:
Operation Result:
4. Batch update test
On the database course, you need to test the acceleration of the index for lookups. However, it is not possible to visually experience the acceleration of the index by operating on a hundreds of or thousands of data volume. Now you want to write a program that inserts 100,000 of data in bulk, and that the contents of some fields in that data can be randomly generated.
4.1 Your code (advent number), statistic run time (use JUINT4 test, need to appear time contrast).
A: 100,000 for the common method to run too long (10,000 actually also a long time), changed to 10,000.
Using 100,000 test data to test the batchtest individually, you can see that the speed is also very fast.
5. Jdbcutil and DAO5.1 complete the pilot task-the 4th point in title 5, which is the writingStudentDaoInterfaces and their implementation classesStudentDaoJDBCImpl。
TestClass:
5.2 What are the benefits of accessing a database using DAO mode? Use the 4.1 code description to compare the traditional pattern with the code that accesses the database using DAO mode.
A: Unlike databases, which use their command statements, using DAO mode to access a database can mask differences in different databases, it only focuses on how to write data to the database and how to remove it, providing good support for the underlying access. In this problem, because only write a method of implementation, so its superiority is not very well reflected, but if we want to use the DAO pattern to access another database, then we just need to write a new implementation class to implement the DAO interface defined method, and then use it can be used according to our needs 接口.实现类statement to choose which database to use, but if we are using the traditional mode, then we have to write two separate programs to achieve this function, not only increase the amount of code, but also not easy to expand and maintain the program.
5.3 Using Jdbcutil to retrofit topic 3.1.
6. Transaction 6.1 Using code and running results proves that you did implement the transaction function and what do you need to be aware of when you encode the transaction?Note:To compare changes to the database in both successful and failed runs. (Paste a code that you think is more valuable, the number of the study)
A: In a database, a transaction is a unit of work consisting of one or more statements that update the database, and the transaction mechanism is that when a transaction is processed, the transaction can be committed to the database only if all the operations in the transaction are completed properly, and if an item is not completed, the work is undone.
In the JDBC API, the system automatically commits transactions by default, so to make multiple statements into a transaction, you have to use the setAutoCommit(false) statement to suppress the commit, and when the whole is normal execution then use ' commit () ' to commit, otherwise you will call the ' rollback () ' method to revoke the transaction.
Data Sheet Contents:
Normal operation:
Abnormal operation:
Datasheet content (find MySQL visual interface easier to use, personal feeling than command line):
6.2 When do you think you need to use transaction processing?
A: In the operation of the database, the transaction is a number of operation statements to form an indivisible whole, only one of the operations are successful to calculate the success of the entire transaction, so to achieve this function, you need to use transaction processing, can be in the event of an error in time to revoke the previous transaction. `
201621123031 Java programming 14th Week of study summary