当前位置: 首页 > news >正文

apache commons-dbcp Apache Commons DBCP 软件实现数据库连接池 commons-dbcp2

DBCP组件

许多Apache项目支持与关系型数据库进行交互。为每个用户创建一个新连接可能很耗时(通常需要多秒钟的时钟时间),以执行可能需要毫秒级时间的数据库事务。对于一个公开托管在互联网上的应用程序,在同时在线用户数量可能非常大的情况下,为每个用户打开一个连接可能是不可行的。因此,开发人员通常希望在所有当前应用程序用户之间共享一组“池化”的打开连接。在任何给定时间实际执行请求的用户数量通常只是活跃用户总数的非常小的百分比,在请求处理期间是唯一需要数据库连接的时间。应用程序本身登录到DBMS,并在内部处理任何用户账户问题。

已经有几个数据库连接池可用,包括Apache产品内部和其他地方。这个Commons包提供了一个机会,来协调创建和维护一个高效、功能丰富的包,以Apache许可证发布。

commons-dbcp2依赖于commons-pool2中的代码,以提供底层的对象池机制。

不同版本

DBCP现在有四个不同的版本,支持不同版本的JDBC。

它的工作原理如下:

开发中

DBCP 2.5.0及以上版本在Java 8(JDBC 4.2)及以上版本下编译和运行。

DBCP 2.4.0在Java 7(JDBC 4.1)及以上版本下编译和运行。

运行中

应用程序运行在Java 8及以上版本的情况下,应使用DBCP 2.5.0及以上版本的二进制文件。 应用程序在Java 7下运行时应使用DBCP 2.4.0的二进制文件。 DBCP 2基于Apache Commons Pool,并提供了与DBCP 1.x相比性能增强、JMX支持以及许多其他新功能。升级到2.x的用户应该注意到Java包名称已更改,以及Maven坐标已更改,因为DBCP 2.x与DBCP 1.x不是二进制兼容的。用户还应该注意,一些配置选项(例如maxActive到maxTotal)已更名以与Commons Pool使用的新名称对齐。

入门例子

您可以从我们的下载页面下载源代码和二进制文件。

或者,您可以从中央 Maven 存储库中提取它:

maven 引入

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-dbcp2</artifactId><version>2.9.0</version>
</dependency>

代码

https://github.com/apache/commons-dbcp/tree/HEAD/doc

BasicDataSourceExample

这个是最基本的例子,不涉及任何池化能力。

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.sql.DataSource;//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDataSource
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.dbcp2.BasicDataSource;//
// Here's a simple example of how to use the BasicDataSource.
////
// Note that this example is very similar to the PoolingDriver
// example.//
// To compile this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
//  * commons-logging-1.2.jar
// in your classpath.
//
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       BasicDataSourceExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class BasicDataSourceExample {public static void main(String[] args) {// First we set up the BasicDataSource.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up data source.");DataSource dataSource = setupDataSource(args[0]);System.out.println("Done.");//// Now, we can use JDBC DataSource as we normally would.//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = dataSource.getConnection();System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}}public static DataSource setupDataSource(String connectURI) {BasicDataSource ds = new BasicDataSource();ds.setDriverClassName("org.h2.Driver");ds.setUrl(connectURI);return ds;}public static void printDataSourceStats(DataSource ds) {BasicDataSource bds = (BasicDataSource) ds;System.out.println("NumActive: " + bds.getNumActive());System.out.println("NumIdle: " + bds.getNumIdle());}public static void shutdownDataSource(DataSource ds) throws SQLException {BasicDataSource bds = (BasicDataSource) ds;bds.close();}
}

PoolingDataSourceExample

这里的 datasource 是池化的。

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDataSource
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolingDataSource;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;//
// Here's a simple example of how to use the PoolingDataSource.
////
// Note that this example is very similar to the PoolingDriver
// example.  In fact, you could use the same pool in both a
// PoolingDriver and a PoolingDataSource
////
// To compile this example, you'll want:
//  * commons-pool2-2.3.jar
//  * commons-dbcp2-2.1.jar
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool2-2.3.jar
//  * commons-dbcp2-2.1.jar
//  * commons-logging-1.2.jar
//  * the classes for your (underlying) JDBC driver
// in your classpath.
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       PoolingDataSourceExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class PoolingDataSourceExample {public static void main(String[] args) {//// First we load the underlying JDBC driver.// You need this if you don't use the jdbc.drivers// system property.//System.out.println("Loading underlying JDBC driver.");try {Class.forName("org.h2.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}System.out.println("Done.");//// Then, we set up the PoolingDataSource.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up data source.");DataSource dataSource = setupDataSource(args[0]);System.out.println("Done.");//// Now, we can use JDBC DataSource as we normally would.//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = dataSource.getConnection();System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}}// 这里的 datasource 是池化的。public static DataSource setupDataSource(String connectURI) {//// First, we'll create a ConnectionFactory that the// pool will use to create Connections.// We'll use the DriverManagerConnectionFactory,// using the connect string passed in the command line// arguments.//ConnectionFactory connectionFactory =new DriverManagerConnectionFactory(connectURI, null);//// Next we'll create the PoolableConnectionFactory, which wraps// the "real" Connections created by the ConnectionFactory with// the classes that implement the pooling functionality.//PoolableConnectionFactory poolableConnectionFactory =new PoolableConnectionFactory(connectionFactory, null);//// Now we'll need a ObjectPool that serves as the// actual pool of connections.//// We'll use a GenericObjectPool instance, although// any ObjectPool implementation will suffice.//ObjectPool<PoolableConnection> connectionPool =new GenericObjectPool<>(poolableConnectionFactory);// Set the factory's pool property to the owning poolpoolableConnectionFactory.setPool(connectionPool);//// Finally, we create the PoolingDriver itself,// passing in the object pool we created.//PoolingDataSource<PoolableConnection> dataSource =new PoolingDataSource<>(connectionPool);return dataSource;}
}

PoolingDriverExample.java

这里用的是 dbcp 的驱动实现池化的?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.PoolingDriver;
//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDriver
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;//
// Here's a simple example of how to use the PoolingDriver.
//// To compile this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
//  * commons-logging-1.2.jar
// in your classpath.
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       PoolingDriverExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class PoolingDriverExample {public static void main(String[] args) {//// First we load the underlying JDBC driver.// You need this if you don't use the jdbc.drivers// system property.//System.out.println("Loading underlying JDBC driver.");try {Class.forName("org.h2.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}System.out.println("Done.");//// Then we set up and register the PoolingDriver.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up driver.");try {setupDriver(args[0]);} catch (Exception e) {e.printStackTrace();}System.out.println("Done.");//// Now, we can use JDBC as we normally would.// Using the connect string//  jdbc:apache:commons:dbcp:example// The general form being://  jdbc:apache:commons:dbcp:<name-of-pool>//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}// Display some pool statisticstry {printDriverStats();} catch (Exception e) {e.printStackTrace();}// closes the pooltry {shutdownDriver();} catch (Exception e) {e.printStackTrace();}}public static void setupDriver(String connectURI) throws Exception {//// First, we'll create a ConnectionFactory that the// pool will use to create Connections.// We'll use the DriverManagerConnectionFactory,// using the connect string passed in the command line// arguments.//ConnectionFactory connectionFactory =new DriverManagerConnectionFactory(connectURI, null);//// Next, we'll create the PoolableConnectionFactory, which wraps// the "real" Connections created by the ConnectionFactory with// the classes that implement the pooling functionality.//PoolableConnectionFactory poolableConnectionFactory =new PoolableConnectionFactory(connectionFactory, null);//// Now we'll need a ObjectPool that serves as the// actual pool of connections.//// We'll use a GenericObjectPool instance, although// any ObjectPool implementation will suffice.//ObjectPool<PoolableConnection> connectionPool =new GenericObjectPool<>(poolableConnectionFactory);// Set the factory's pool property to the owning poolpoolableConnectionFactory.setPool(connectionPool);//// Finally, we create the PoolingDriver itself...//Class.forName("org.apache.commons.dbcp2.PoolingDriver");PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");//// ...and register our pool with it.//driver.registerPool("example", connectionPool);//// Now we can just use the connect string "jdbc:apache:commons:dbcp:example"// to access our pool of Connections.//}public static void printDriverStats() throws Exception {PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");ObjectPool<? extends Connection> connectionPool = driver.getConnectionPool("example");System.out.println("NumActive: " + connectionPool.getNumActive());System.out.println("NumIdle: " + connectionPool.getNumIdle());}public static void shutdownDriver() throws Exception {PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");driver.closePool("example");}
}

相关文章:

apache commons-dbcp Apache Commons DBCP 软件实现数据库连接池 commons-dbcp2

DBCP组件 许多Apache项目支持与关系型数据库进行交互。为每个用户创建一个新连接可能很耗时&#xff08;通常需要多秒钟的时钟时间&#xff09;&#xff0c;以执行可能需要毫秒级时间的数据库事务。对于一个公开托管在互联网上的应用程序&#xff0c;在同时在线用户数量可能非…...

8.2K star!史上最强Web应用防火墙

&#x1f6a9; 0x01 介绍 长亭雷池SafeLine是长亭科技耗时近 10 年倾情打造的WAF(Web Application Firewall)&#xff0c;一款敢打出口号 “不让黑客越雷池一步” 的 WAF&#xff0c;我愿称之为史上最强的一款Web应用防火墙&#xff0c;足够简单、足够好用、足够强的免费且开源…...

浅谈RPC的理解

浅谈RPC的理解 前言RPC体系Dubbo架构最后 前言 本文中部分知识涉及Dubbo&#xff0c;需要对Dubbo有一定的理解&#xff0c;且对源码有一定了解 如果不了解&#xff0c;可以参考学习我之前的文章&#xff1a; 浅谈Spring整合Dubbo源码&#xff08;Service和Reference注解部分&am…...

JDK发布信息、历史及未来规划

1.未来规划 发布日期类型版本其它信息2026-01-20CPU25.0.2, 21.0.10, 17.0.18, 11.0.30, 8u4812025-10-21CPU25.0.1, 21.0.9, 17.0.17, 11.0.29, 8u4712025-09-16Feature*25 LTS2025-07-15CPU24.0.2, 21.0.8, 17.0.16, 11.0.28, 8u4612025-04-15CPU24.0.1, 21.0.7, 17.0.15, 1…...

帅帅密码管理系统使用教程

在这个账号满天飞的大环境&#xff0c;密码太多&#xff0c;又容易遗忘&#xff0c;又不方便管理&#xff0c;存在记事本上&#xff0c;又担心泄漏。帅帅密码管理系统就是帮助你解决以上烦恼&#xff0c;用来帮助个人或团队管理众多的登陆密码&#xff0c;能够快速的查询、新增…...

漫谈5种注册中心

01 注册中心基本概念 1.1 什么是注册中心&#xff1f; 注册中心主要有三种角色&#xff1a; 服务提供者&#xff08;RPC Server&#xff09;&#xff1a;在启动时&#xff0c;向 Registry 注册自身服务&#xff0c;并向 Registry 定期发送心跳汇报存活状态。 服务消费者&…...

Vulnhub靶机:Kioptrix_2014

一、介绍 运行环境&#xff1a;Virtualbox和vmware 攻击机&#xff1a;kali&#xff08;192.168.56.101&#xff09; 靶机&#xff1a;Kioptrix: 2014&#xff08;192.168.56.108&#xff09; 目标&#xff1a;获取靶机root权限和flag 靶机下载地址&#xff1a;https://ww…...

Spring Boot整合Spring Security

Spring Boot 专栏&#xff1a;Spring Boot 从零单排 Spring Cloud 专栏&#xff1a;Spring Cloud 从零单排 GitHub&#xff1a;SpringBootDemo Gitee&#xff1a;SpringBootDemo Spring Security是针对Spring项目的安全框架&#xff0c;也是Spring Boot底层安全模块的默认技术…...

Rust字符串深入理解

一、概述 Rust是一种系统级语言&#xff0c;进行操作系统等底层应用开发&#xff0c;同时又具合理的抽象处理能力。在进行Rust编程时&#xff0c;字符串处理是程序员经常碰到的工作。本文深入解析Rust语言中字符串的使用&#xff0c;包括 static string&#xff0c;String与&a…...

TSINGSEE青犀AI智能分析网关V4酿酒厂安全挂网AI检测算法

在酿酒行业中&#xff0c;安全生产一直是企业经营中至关重要的一环。为了确保酒厂生产过程中的安全&#xff0c;TSINGSEE青犀AI智能分析网关V4的安全挂网AI检测算法发挥了重要作用。 TSINGSEE青犀AI智能分析网关V4的安全挂网检测算法是针对酒厂里酒窖挂网行为进行智能检测与识…...

LeetCode第126场双周赛个人题解

目录 100262. 求出加密整数的和 原题链接 思路分析 AC代码 3080. 执行操作标记数组中的元素 原题链接 思路分析 AC代码 100249. 替换字符串中的问号使分数最小 原题链接 思路分析 AC代码 100241. 求出所有子序列的能量和 原题链接 思路分析 AC代码 100262. 求出…...

牛客NC403 编辑距离为一【中等 模拟法 Java,Go,PHP】

题目 题目链接&#xff1a; https://www.nowcoder.com/practice/0b4b22ae020247ba8ac086674f1bd2bc 思路 注意&#xff1a;必须要新增一个&#xff0c;或者删除一个&#xff0c;或者替换一个&#xff0c;所以不能相等1.如果s和t相等&#xff0c;返回false,如果s和t长度差大于1…...

C# SetWindowPos函数

在C#中&#xff0c;SetWindowPos函数用于设置窗口的位置和大小。 原型&#xff1a; [DllImport("user32.dll", SetLastError true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int …...

zookeeper快速入门五:用zookeeper实现服务注册与发现中心

系列&#xff1a; zookeeper快速入门一&#xff1a;zookeeper安装与启动-CSDN博客 zookeeper快速入门二&#xff1a;zookeeper基本概念-CSDN博客 zookeeper快速入门三&#xff1a;zookeeper的基本操作 zookeeper快速入门四&#xff1a;在java客户端中操作zookeeper-CSDN博客…...

Java 中 BitSet 类的用法

Java 中 BitSet 类的用法 API构造置位为 true清除为 false查找位反转长度运算流其他 原理底层数据结构如何工作 API 构造 无参构造 &#xff1a;默认为 64 个 bit 的容量 BitSet bitset new BitSet();有参构造 &#xff1a;设置为 n 个 bit 的容量 BitSet bitset new BitSe…...

Jenkins-pipeline流水线构建完钉钉通知

添加钉钉机器人 在钉钉群设置里添加机器人拿出Webhook地址&#xff0c;设置关键词 Jenkins安装钉钉插件 Dashboard > 系统管理 > 插件管理&#xff0c;搜索构建通知&#xff0c;直接搜索Ding Talk也行 安装DingTalk插件&#xff0c;重启Jenkins 来到Dashboard > 系…...

汽车制造业供应商管理会面临哪些问题?要如何解决?

汽车行业的供应链是及其复杂的&#xff0c;并且呈全球化分布&#xff0c;企业在知识产权方面的优势很可能是阶段性的。企业需要持续保持领先&#xff0c;将面临巨大的挑战&#xff0c;尽快地将产品推向市场是保持领先的唯一途径。然而&#xff0c;如果没有正确的方式去实现安全…...

day28|93. 复原 IP 地址|Leetcode 78. 子集|90.子集II

Leetcode 93. 复原 IP 地址 链接&#xff1a;93. 复原 IP 地址 class Solution { public:vector<string> res;string path;int pointNum 0;vector<string> restoreIpAddresses(string s) {backtracking(0, s);return res;}void backtracking(int start, string …...

怎样提升小程序日活?签到抽奖可行吗?

一、 日活运营策略 小程序应该是即用即走的&#xff0c;每个小程序都在用户中有自己的独特定位&#xff0c;可能是生活日常必备&#xff08;美食、团购、商城&#xff09;&#xff0c;也可能是工作办公必备&#xff08;文档、打卡、工具&#xff09;。 如果你想要让自己的小程…...

hive语法树分析,判断 sql语句中有没有select *

pom依赖参考以下博文java 通过 IMetaStoreClient 取 hive 元数据信息-CSDN博客1 节点处理器类 import lombok.Getter; import org.apache.hadoop.hive.ql.lib.Dispatcher; import org.apache.hadoop.hive.ql.lib.Node; import org.apache.hadoop.hive.ql.parse.ASTNode; impor…...

python/java环境配置

环境变量放一起 python&#xff1a; 1.首先下载Python Python下载地址&#xff1a;Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个&#xff0c;然后自定义&#xff0c;全选 可以把前4个选上 3.环境配置 1&#xff09;搜高级系统设置 2…...

多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验

一、多模态商品数据接口的技术架构 &#xff08;一&#xff09;多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如&#xff0c;当用户上传一张“蓝色连衣裙”的图片时&#xff0c;接口可自动提取图像中的颜色&#xff08;RGB值&…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

Android15默认授权浮窗权限

我们经常有那种需求&#xff0c;客户需要定制的apk集成在ROM中&#xff0c;并且默认授予其【显示在其他应用的上层】权限&#xff0c;也就是我们常说的浮窗权限&#xff0c;那么我们就可以通过以下方法在wms、ams等系统服务的systemReady()方法中调用即可实现预置应用默认授权浮…...

3403. 从盒子中找出字典序最大的字符串 I

3403. 从盒子中找出字典序最大的字符串 I 题目链接&#xff1a;3403. 从盒子中找出字典序最大的字符串 I 代码如下&#xff1a; class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...

SpringTask-03.入门案例

一.入门案例 启动类&#xff1a; package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...

项目部署到Linux上时遇到的错误(Redis,MySQL,无法正确连接,地址占用问题)

Redis无法正确连接 在运行jar包时出现了这样的错误 查询得知问题核心在于Redis连接失败&#xff0c;具体原因是客户端发送了密码认证请求&#xff0c;但Redis服务器未设置密码 1.为Redis设置密码&#xff08;匹配客户端配置&#xff09; 步骤&#xff1a; 1&#xff09;.修…...

USB Over IP专用硬件的5个特点

USB over IP技术通过将USB协议数据封装在标准TCP/IP网络数据包中&#xff0c;从根本上改变了USB连接。这允许客户端通过局域网或广域网远程访问和控制物理连接到服务器的USB设备&#xff08;如专用硬件设备&#xff09;&#xff0c;从而消除了直接物理连接的需要。USB over IP的…...

排序算法总结(C++)

目录 一、稳定性二、排序算法选择、冒泡、插入排序归并排序随机快速排序堆排序基数排序计数排序 三、总结 一、稳定性 排序算法的稳定性是指&#xff1a;同样大小的样本 **&#xff08;同样大小的数据&#xff09;**在排序之后不会改变原始的相对次序。 稳定性对基础类型对象…...

力扣热题100 k个一组反转链表题解

题目: 代码: func reverseKGroup(head *ListNode, k int) *ListNode {cur : headfor i : 0; i < k; i {if cur nil {return head}cur cur.Next}newHead : reverse(head, cur)head.Next reverseKGroup(cur, k)return newHead }func reverse(start, end *ListNode) *ListN…...