c3p0连接池模板
连接池是创建和管理一个连接的缓冲池的技术,这些连接准备好被任何需要它们的线程使用。 我现在做一个p3c0连接池的模板。 首先p3c0是开源的,所以去官网下载p3c0的jar包。在工程中导入,同时要下载你连接数据库的驱动 连接池模板代码如下: package com.fish
连接池是创建和管理一个连接的缓冲池的技术,这些连接准备好被任何需要它们的线程使用。
我现在做一个p3c0连接池的模板。
首先p3c0是开源的,所以去官网下载p3c0的jar包。在工程中导入,同时要下载你连接数据库的驱动
连接池模板代码如下:
package com.fish; import java.beans.PropertyVetoException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ResourceBundle; import com.mchange.v2.c3p0.ComboPooledDataSource; /** * 连接数据库的工具类,被定义成不可继承且是私有访问 */ public final class DBTool { //采用配置文件的方式配置连接池的一些信心,这个是配置文件的名字 final private static String OPTION_FILE_NAME = "mysqldatabase"; private static Connection conn; static ResourceBundle res; //连接池的类 static ComboPooledDataSource cpds; static { //从配置文件中获取文件 res = ResourceBundle.getBundle(OPTION_FILE_NAME); //创建一个连接池 cpds = new ComboPooledDataSource(); //驱动名 String driver = res.getString("jdbc.driver"); //连接url String url = res.getString("jdbc.url"); //数据库用户名 String user = res.getString("jdbc.username"); //数据库密码 String password = res.getString("jdbc.password"); //连接池的最大连接数 String poolMax = res.getString("c3p0.maxPoolSize"); //连接池的最小连接数 String poolMin = res.getString("c3p0.minPoolSize"); //当资源用尽时,允许连接的数目 String PoolAcquireIncrement = res.getString("c3p0.acquireIncrement"); try { cpds.setDriverClass(driver); } catch (PropertyVetoException e) { System.out.println("驱动没找到"); } cpds.setJdbcUrl(url); cpds.setUser(user); cpds.setPassword(password); cpds.setMinPoolSize(Integer.parseInt(poolMin)); cpds.setAcquireIncrement(Integer.parseInt(PoolAcquireIncrement)); cpds.setMaxPoolSize(Integer.parseInt(poolMax)); } /** * 获取数据库的连接 * * @return conn */ public static Connection getConnection() { try { conn = cpds.getConnection(); } catch (SQLException e) { System.out.println("连接失败"); } return conn; } /** * 释放资源 * */ public static void closeJDBC(Connection conn, Statement statement, ResultSet rs) { if (null != rs) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (null != statement) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (null != conn) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } } } } } } } }
2.mysqldatabase.properties文件如下:
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/datacenter3 jdbc.username=root jdbc.password=1234 c3p0.maxPoolSize = 30 c3p0.minPoolSize = 10 c3p0.acquireIncrement =10 以后你要连接什么数据库直接在这个文件里面修改。 测试:例子 package com.fish; public class Test2 { public static void main(String[] args) throws Exception { System.out.println(DBTool.getConnection()); } } 输出结果: 2014-11-16 14:44:04 com.mchange.v2.log.MLog <clinit> 信息: MLog clients using java 1.4+ standard logging. 2014-11-16 14:44:04 com.mchange.v2.c3p0.C3P0Registry banner 信息: Initializing c3p0-0.9.2.1 [built 20-March-2013 11:16:28 +0000; debug? true; trace: 10] 2014-11-16 14:44:04 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager 信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 10, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge1d1951evdfumup12ui|5ffb18, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge1d1951evdfumup12ui|5ffb18, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/datacenter3, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] com.mchange.v2.c3p0.impl.NewProxyConnection@d19bc8

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This article will explain in detail how PHP formats rows into CSV and writes file pointers. I think it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Format rows to CSV and write to file pointer Step 1: Open file pointer $file=fopen("path/to/file.csv","w"); Step 2: Convert rows to CSV string using fputcsv( ) function converts rows to CSV strings. The function accepts the following parameters: $file: file pointer $fields: CSV fields as an array $delimiter: field delimiter (optional) $enclosure: field quotes (

How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

StableDiffusion3’s paper is finally here! This model was released two weeks ago and uses the same DiT (DiffusionTransformer) architecture as Sora. It caused quite a stir once it was released. Compared with the previous version, the quality of the images generated by StableDiffusion3 has been significantly improved. It now supports multi-theme prompts, and the text writing effect has also been improved, and garbled characters no longer appear. StabilityAI pointed out that StableDiffusion3 is a series of models with parameter sizes ranging from 800M to 8B. This parameter range means that the model can be run directly on many portable devices, significantly reducing the use of AI

This paper explores the problem of accurately detecting objects from different viewing angles (such as perspective and bird's-eye view) in autonomous driving, especially how to effectively transform features from perspective (PV) to bird's-eye view (BEV) space. Transformation is implemented via the Visual Transformation (VT) module. Existing methods are broadly divided into two strategies: 2D to 3D and 3D to 2D conversion. 2D-to-3D methods improve dense 2D features by predicting depth probabilities, but the inherent uncertainty of depth predictions, especially in distant regions, may introduce inaccuracies. While 3D to 2D methods usually use 3D queries to sample 2D features and learn the attention weights of the correspondence between 3D and 2D features through a Transformer, which increases the computational and deployment time.

When you use the Edge browser to access web pages, have you ever encountered a prompt that your connection is not a dedicated connection, causing web browsing to fail? How is this going? Many friends don’t know how to deal with this problem. You can take a look at the following three solutions. Method 1 (simple and crude): In the edge browser, you can try to solve the problem of the website being inaccessible by entering the settings and turning off the security function, and then blocking location permissions in the website permissions. It is important to note that the effectiveness and duration of this approach may vary, and specific effects cannot be determined. After restarting your browser, you can try visiting the website to see if the issue is resolved. Method 2: Adjust the keyboard to English input

1. Place the earphones in the earphone box and keep the lid open. Press and hold the button on the box to enter the pairing state of the earphones. 2. Turn on the watch music function and select Bluetooth headphones, or select Bluetooth headphones in the watch settings function. 3. Select the headset on the watch to pair successfully.

In September 23, the paper "DeepModelFusion:ASurvey" was published by the National University of Defense Technology, JD.com and Beijing Institute of Technology. Deep model fusion/merging is an emerging technology that combines the parameters or predictions of multiple deep learning models into a single model. It combines the capabilities of different models to compensate for the biases and errors of individual models for better performance. Deep model fusion on large-scale deep learning models (such as LLM and basic models) faces some challenges, including high computational cost, high-dimensional parameter space, interference between different heterogeneous models, etc. This article divides existing deep model fusion methods into four categories: (1) "Pattern connection", which connects solutions in the weight space through a loss-reducing path to obtain a better initial model fusion

On January 23, 2024, Beijing time, NVIDIARTXRemix was fully launched for public testing. Download link: https://www.nvidia.cn/geforce/rtx-remix/What is RTXRemix? It is a free mod platform based on NVIDIA Omniverse, dedicated to helping modders quickly create and share #RTXON versions of classic old games. We can simply understand it as an external program, which will not change the engine of old games; rather, it will not change the engine of old games; Take over a series of tools such as graphics rendering pipeline/scene management while the game is running, and combine it with NVIDIA full ray tracing, DLSS, Reflex and other technologies to achieve significant changes.
