The PreparedStatement interface inherits from the Statement interface
PreparedStatement is recommended instead of Statement
Advantages of Preparedstatement:
-
Prevents SQL injection
-
Faster execution than Statement
-
Support batch processing
Some values that are frequently dynamically modified are recommended to be placed in a configuration file and not written to death in Java code
-
Because. java compiled to. class, cannot modify its contents directly
-
Deployed projects need to modify Java code to redeploy if they want to modify configuration information
Configuration files commonly used in Java:
-
properties: single, suitable for small, simple configurations
-
xml: flexible and suitable for large and complex configurations
Properrties file:
-
The separator for key, value is = or:
-
It is recommended that no space be left around the separator
-
#,! Begins with a single line comment
-
Multiple lines of content can be connected with backslashes\
Database connection pooling, which improves performance in accessing databases, is responsible for creating, assigning, managing, and releasing database connections
Basic Ideas:
-
When initializing, create a certain number of database connection objects to store in memory
-
When accessing a database, instead of creating a new connection, pull a free connection object from the connection pool that has been created
-
When finished, the user does not close the connection, but puts it back into the connection pool for the next request access
-
When a connection has been idle for more than the maximum idle time, the connection will be released
-
Parameters can be set to control the number of initial connections, the upper and lower limits of connections, and the maximum number of times each connection is used, and the maximum idle time.
-
You can monitor the number and usage of database connections through your own management mechanisms
Common open source database connection pools in Java:
- C3P0, Proxool, DBCP, BoneCP, Druid, etc.
Druid is produced in Alibaba, project address: https://github.com/alibaba/druid/
jar package download: https://mvnrepository.com/artifact/com.alibaba/druid
==============================================================================
Sample code: https://gitee.com/szluyu99/mj_java/tree/master/06_crm_Spring-JDBC
Spring JDBC Framework can help developers save a lot of development work by automatically handling low-level details such as
- Exception handling, opening and closing resources (Connection, Statement, ResultSet)
Required jar packages:
-
spring-jdbc
-
spring-beans
-
spring-core
-
spring-tx
-
spring-jcl
Spring JDBC Core Class: JdbcTemplate
Construction method:
public JdbcTemplate(DataSource datasource)
Execute DDL, DML statements:
int update(String sql, Object... args)
Execute the DQL statement:
<T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) <T> queryForObject(String sql, RowMapper<T> rowMapper, Object... args)
========================================================================
Sample code: https://gitee.com/szluyu99/mj_java/blob/master/06_crm_Spring-JDBC/test/com/mj/test/CustomerDaoTest.java
JUnit is the most common open source framework for unit testing in Java, and this course uses version 4.13
Required jar packages:
-
junit-4.13
-
hamcrest-core-2.2
-
hamcrest-2.2
Recommended format for naming unit test classes is: XxTest
@Test: Normal test method, recommended format:
public void testXx()
@Before: Executed before each @Test method is executed, recommended format:
public void before()
@After: After each @Test method is executed, the recommended format is:
public void after()
@BeforeClass: Before the first @Test method is executed, the recommended format is:
public static void beforeClass()
@AfterClass: After the last @Test method executes, the recommended format is:
public static void afterClass()
Common methods for asserting class Assert
assertTrue assertFalse assertEquals assertNotEquals assertNotNull # summary Ant interviews are more basic, so Java Those basic skills must be solid. The working environment of ants is still very good, because I have a stability assurance department in front of me, and there are many separate groups, which have three years and one class, and I feel very young. The basic level of interviewers is high, almost all P7 In addition to the basics, there are a number of architecture design issues that have been asked, but the benefits are still substantial. **[Data collection method: Stamp here](https://gitee.com/vip204888/java-p7)** * * * **After this interview, I also found through some channels that the main need for real factory interviews is**: Ant Golden Clothes, Pindo, Ali Yun, Baidu, Weiyi Hui, Ctrip, Fengchao Technology, Letter, Soft Power, OPPO,Yinsheng Payment, Ping'an in China, Junior, Intermediate, Advanced Java Collection of interview questions, with ultra-detailed answers, I hope to help you. Ant interviews are more basic, so Java Those basic skills must be solid. The working environment of ants is still very good, because I have a stability assurance department in front of me, and there are many separate groups, which have three years and one class, and I feel very young. The basic level of interviewers is high, almost all P7 In addition to the basics, there are a number of architecture design issues that have been asked, but the benefits are still substantial. **[Data collection method: Stamp here](https://gitee.com/vip204888/java-p7)** * * * **After this interview, I also found through some channels that the main need for real factory interviews is**: Ant Golden Clothes, Pindo, Ali Yun, Baidu, Weiyi Hui, Ctrip, Fengchao Technology, Letter, Soft Power, OPPO,Yinsheng Payment, Ping'an in China, Junior, Intermediate, Advanced Java Collection of interview questions, with ultra-detailed answers, I hope to help you. ![Ant Golden Clothes 5 sides, summarizing 49 interview questions, interviewers encountered are P7 Above level](https://img-blog.csdnimg.cn/img_convert/a8bc86de3c451c2e1fab0dcc16a5839f.png)