jdbc data source (DruidDataSourceFactory) connection pool – druid

<dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.16</version> </dependency> </dependencies> 1. Druid data source connection pool technology package com.csdn.jdbc; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidPooledConnection; import java.sql.SQLException; // Demonstrate data source connection pool druid Druid data source connection pool technology public class DataSourceConnectPool { public static void main(String[] args) throws SQLException { DruidDataSource dataSource […]

Solve the problem that sharding jdbc cannot update data in batches

Background: After integrating sharding jdbc, the following problems occur when batch modification of table data that has been divided into tables: The first modified data SQL statement was rewritten from sharding to the corresponding table name. All subsequent SQL table names were not rewritten, causing the batch modification to fail. Baidu has found relevant information. […]

Upgrade the fruit inventory system using jdbc technology (final version of the backend, not including the frontend)

1. Configuration dependencies <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.16</version> </dependency> </dependencies> 2. Fruit entity class package com.csdn.fruit.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; @Data @NoArgsConstructor @AllArgsConstructor public class Fruit implements Serializable { private Integer fid; private String fname; […]

jdbc uses data source connection pool technology to upgrade BaseDao

jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql:///fruitdb jdbc.user=root jdbc.pwd=123456 jdbc.init_size=5 jdbc.max_active=20 jdbc.max_wait=3000 package com.csdn.mymvc.dao; import com.alibaba.druid.pool.DruidDataSource; import com.csdn.mymvc.util.ClassUtil; import javax.sql.DataSource; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.sql.*; import java.util.ArrayList; import java.util.List; import java.util.Properties; public abstract class BaseDao<T> { private String entityClassName; public BaseDao() { //Who is this? This represents the instance object of FruitDaoImpl. Because BaseDao is […]

JDBC connection parameter configuration

Article directory 1. Oracle – the relationship between database instances, table spaces, users, and tables 0. Database: 1. Example 2. Table space 3. User 4. Table 5. Association 2. Mysql – relationships between databases, users, and tables 1. Database 2. User 3. Table 4. Association 3. JDBC database connection configuration 1. driver 2.URL 3. User […]

JDBC database connection pool

JDBC database connection pool 1. Overview of database connection pool In JDBC programming, each time a Connection object is created and disconnected, a certain amount of time and IO resources will be consumed. When establishing a connection between a Java program and a database, the database side must verify the user name and password and […]

jdbc support for transactions

The automatic transaction submission function is enabled by default in MySQL, that is, each SQL statement will automatically open a transaction and submit it. If the COMMIT or ROLLBACK statement is not explicitly used, all modifications will be saved to the database. In this case, if an error occurs in an operation, the transaction cannot […]

Flink writes data to MySQL (JDBC)

1. Write in front In actual production environments, we often write data processed by Flink into databases such as MySQL and Doris. Taking MySQL as an example, we use JDBC to write real-time Flink data into MySQL. 2. Code examples 2.1 Release Notes <flink.version>1.14.6</flink.version> <spark.version>2.4.3</spark.version> <hadoop.version>2.8.5</hadoop.version> <hbase.version>1.4.9</hbase.version> <hive.version>2.3.5</hive.version> <java.version>1.8</java.version> <scala.version>2.11.8</scala.version> <mysql.version>8.0.22</mysql.version> <scala.binary.version>2.11</scala.binary.version> 2.2 Import related […]

MySQL—JDBC programming

Article directory What is JDBC? How JDBC works Use of JDBC Add driver Create data sourceDataSource Create database connection Connection Create operation command Statement Execute SQL instructions Release resources Demo CRUD via JDBC New Query (requires an additional step to traverse the result set) Revise delete What is JDBC? JDBC: Java Database Connectivity, that is, […]