. Loop execution not in use jdbc Under the premise of batch operation
For batch operation, you can Relative efficiency jdbc Lower batch operation
The normal loop operation code is as follows :
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root",
"root"); // String sql = "update user set power=? where username=?"; String sql
= "insert into user values (???)"; //delete , insert and update Are similar calls
executeUpdate method //3 Get processor long start = System.currentTimeMillis(); for (int i =
0; i < 100; i++) { statement = conn.prepareStatement(sql); // Injection value The number is the question mark ? from 1 start
statement.setString(1, " Zhao Shuo "+i); statement.setString(2, " Zhao Shuo "+i); statement.setInt
(3, 3); //4 Get affected rows int result = statement.executeUpdate(); } System.out.println(
This implementation efficiency is low , My computer is plugged in 100 Data entry about 197ms.

Let's take a look jdbc Default batch operation method of .
Relative to the first batch operation , More efficient
long start = System.currentTimeMillis(); statement = conn.prepareStatement(sql)
; for (int i = 0; i < 100; i++) {// 197ms // Injection value The number is the question mark ? from 1 start statement.
setString(1, " Zhao Shuo "+i); statement.setString(2, " Zhao Shuo "+i); statement.setInt(3, 3);
statement.addBatch();// Add to batch operation } //4 Get affected rows Array returned int [] result = statement.
executeBatch(); System.out.println(System.currentTimeMillis()-start);

It's more efficient here , insert 100 It costs about 155ms, It can be seen that the efficiency is still very poor . After all, there are only 100 Data . If you are not clear about the amount of data , You can have a look at Baidu's search engine , I'll search it “ computer ” Let's use the term .

You can see 100 million light results , If it's a lot of keyword search , That's tens of billions , Hundreds of billions up to the order of magnitude you can't imagine . Think about the difference in efficiency between the two .

Then let's talk about the common methods of result set
ResultSet resultSet // Get the field value of the corresponding type in the result set // resultSet.getXXX //
resultSet.getString(" Field name ") // resultSet.getString(index) resultSet.getInt(
columnIndex) resultSet.getDate(columnIndex) // You can use when you do not know the field type resultSet.
getObject(columnIndex) // Get all the information in the result set ResultSetMetaData rsmd = resultSet.
getMetaData(); // How many columns are there in the result set rsmd.getColumnCount(); // Gets the column of the specified column rsmd.getColumnName(
column); // Gets the type of the specified column rsmd.getColumnType(column) // Gets the name of the specified column type rsmd.

©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple )os Simple use of module Browser kernel ( understand ) Some East 14 Pay change 16 salary , Sincerity or routine ?HashMap Explain in detail It's unexpected Python Cherry tree (turtle The gorgeous style of Library )html Writing about cherry trees , Writing about cherry trees