11.1

学习了数据库连接池的使用
import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class JavaMySQLConnectionPoolExample {
public static void main(String[] args) {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase");
dataSource.setUser("username");
dataSource.setPassword("password");
Connection connection = dataSource.getConnection();
// Perform database operations here
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

posted @ 2024-11-01 20:55  霸王鸡  阅读(9)  评论(0)    收藏  举报