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

jdbc源码研究

JDBC介绍

JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。

开发者不必为每家数据通信协议的不同而疲于奔命,只需要面向JDBC提供的接口编程,在运行时,由对应的驱动程序操作对应的DB。

java.sql 包中包含用于以下方面的 API:

  • 通过DriverManager实用程序建立与数据库的连接

    • DriverManager 类:建立与驱动程序的连接
    • SQLPermission 类:当代码在 Security Manager(比如 applet)中运行时提供权限,试图通过 DriverManager 设置一个记录流
    • Driver 接口:提供用来注册和连接基于 JDBC 技术(“JDBC 驱动程序”)的驱动程序的 API,通常仅由 DriverManager 类使用
    • DriverPropertyInfo 类:提供 JDBC 驱动程序的属性,不是供一般用户使用的
  • 向数据库发送 SQL 语句

    • Statement:用于发送基本 SQL 语句
    • PreparedStatement:用于发送准备好的语句或基本 SQL 语句(派生自 Statement
    • CallableStatement:用于调用数据库存储过程(派生自 PreparedStatement
    • Connection 接口:提供创建语句以及管理连接及其属性的方法
    • Savepoint:在事务中提供保存点
  • 获取和更新查询的结果

    • ResultSet 接口
  • SQL 类型到 Java 编程语言中的类和接口的标准映射关系

    • Array 接口:SQL ARRAY 的映射关系
    • Blob 接口:SQL BLOB 的映射关系
    • Clob 接口:SQL CLOB 的映射关系
    • Date 类:SQL DATE 的映射关系
    • NClob 接口:SQL NCLOB 的映射关系
    • Ref 接口:SQL REF 的映射关系
    • RowId 接口:SQL ROWID 的映射关系
    • Struct 接口:SQL STRUCT 的映射关系
    • SQLXML 接口:SQL XML 的映射关系
    • Time 类:SQL TIME 的映射关系
    • Timestamp 类:SQL TIMESTAMP 的映射关系
    • Types 类:提供用于 SQL 类型的常量
  • 自定义映射 SQL 用户定义类型 (UDT) 到 Java 编程语言中的类

    • SQLData 接口:指定 UDT 到此类的一个实例的映射关系
    • SQLInput 接口:提供用来从流中读取 UDT 属性的方法
    • SQLOutput 接口:提供用来将 UDT 属性写回流中的方法
  • 元数据

    • DatabaseMetaData 接口:提供有关数据库的信息
    • ResultSetMetaData 接口:提供有关 ResultSet 对象的列的信息
    • ParameterMetaData 接口:提供有关 PreparedStatement 命令的参数的信息
  • 异常

    • SQLException:由大多数方法在访问数据出问题时抛出,以及因为其他原因由其他一些方法抛出
    • SQLWarning:为了指示一个警告而抛出
    • DataTruncation:为了指示数据可能已经被截断而抛出
    • BatchUpdateException:为了指示并不是批量更新中的所有命令都成功执行而抛出

JDBC 的操作步骤

在进行JDBC 操作的时候可以按照以下的步骤完成:

  1. 加载数据库驱动程序,加载的时候需要将驱动程序配置到classpath之中
  2. 连接数据库,通过Connection 接口和 DriverManager 类完成
  3. 操作数据库,通过StatementPreparedStatementResultSet 三个接口完成
  4. 关闭数据库,在实际开发中数据库资源非常有限,操作完之后必须关闭

在JDBC 的操作中,如果要想进行数据库的连接,则必须按照以上的几步完成

  1. 通过Class.forName()加载数据库的驱动程序
  2. 通过DriverManager 类进行数据库的连接,连接的时候要输入数据库的连接地址、用户名、密码
  3. 通过Connection 接口接收连接
  4. 通过Statement接口操作数据。

代码示例

1、引入驱动

        <dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.15</version></dependency>

2、加载驱动

3、建立与数据库的连接

4、创建Statement

Connection接口的createStatement()方法用于创建语句对象(Statement )。 Statement 对象负责对数据库执行查询。

5、执行SQL语句

6、关闭连接

public static void main(String[] args) {//连接对象Connection conn = null;//SQL statement 对象Statement stmt = null;try {//加载驱动Class.forName("com.mysql.cj.jdbc.Driver");//创建连接对象conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT","root", "root");//创建Statementstmt = conn.createStatement();System.out.println("连接成功,获取连接对象: " + conn);//执行SQL语句String sql = "update a set x = x +6 where id > 6";int count = stmt.executeUpdate(sql);System.out.println("返回结果count:" + count);} catch (ClassNotFoundException | SQLException e) {e.printStackTrace();} finally {//05、关闭连接对象if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}

1、驱动类com.mysql.jdbc.Driver 已被弃用。 新的驱动程序类是com.mysql.cj.jdbc.Driver。 驱动程序通过SPI自动注册,通常不需要手动加载驱动程序类。

2、从JDBC 4.0开始,显式注册驱动程序是可选的。 我们只需要将相应的驱动jar放在类路径中,然后JDBC驱动程序管理器就可以自动检测并加载驱动程序。

3、因为新版本的数据库驱动需要指定UTC时区,将url地址后加上时区即可解决,jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT

4、从Java 7开始,JDBC能够使用try-with-resources语句来自动关闭ConnectionResultSetStatement类型的资源。

Java接口定义

Jdbc的主要接口定义在包java.sqljavax.sql下.

主要接口

  • DriverManager: 管理驱动程序,主要用于调用驱动从数据库获取连接。
  • Connection: 代表了一个数据库连接。
  • Statement: 持有Sql语句,执行并返回执行后的结果。
  • ResulSet: Sql执行完毕,返回的记过持有

接口定义

DriverManager

DriverManager 是用于管理JDBC驱动程序的基础服务。DriverManger 可以注册、删除、加载的驱动程序,可以根据给定的url获取符合url协议的驱动Driver 并建立Conenction连接,进行数据库交互。当DriverManager被使用时,DriverManager类将尝试加载“ jdbc.drivers”系统属性中的驱动程序类。

JDBC 4.0驱动程序必须包含文件 META-INF/services/java.sql.Driver,该文件包含了实现java.sql.Driver的JDBC驱动程序的名称。例如,要加载my.sql.Driver类,META-INF/services/java.sql.Driver文件中将包含以下内容:my.sql.Driver

使用DriverManager之后,应用程序不再需要使用 Class.forName() 显式加载JDBC驱动程序了。已经使用 Class.forName() 显式加载JDBC驱动的程序也不会受到影响,也无需刻意去修改。

当调用方法getConnection时,DriverManager将尝试从初始化时加载的驱动程序和当前应用程序显式加载的驱动程序中找到合适的驱动程序。

public interface Driver {/**尝试建立给定URL的数据库连接。 如果驱动程序意识到连接到给定URL的驱动程序类型错误,则应返回“ null”。 这是很常见的,因为当要求JDBC驱动程序管理器连接到给定的URL时,它将URL依次传递给每个已加载的驱动程序。注意:如果将属性指定为url的一部分,并且也在Properties对象中指定了属性,则该实现将由实现定义,以哪个值优先。 为了获得最大的可移植性,应用程序应仅指定一次属性。*/Connection connect(String url, java.util.Properties info)throws SQLException;/**
检索驱动程序是可以打开 给定URL的连接。 通常,如果驱动程序识别出 URL中指定的子协议,则将返回true;否则,将返回false。*/boolean acceptsURL(String url) throws SQLException;/**获取有关此驱动程序可能的属性的信息。getPropertyInfo方法旨在允许通用的GUI工具发现应该提示的属性,以便获得足够的信息以连接到数据库。 */DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)throws SQLException;/**获取驱动程序的主版本号。 最初应为1。*/int getMajorVersion();int getMinorVersion();/**报告此驱动程序是否是正版JDBC Compliant™驱动程序。 如果驱动程序通过了JDBC兼容性测试,则仅在此处报告true。 否则需要返回false。JDBC合规性要求对JDBC API的完全支持和对SQL 92 Entry Level的完全支持。 期望所有主要的商业数据库都可以使用符合JDBC的驱动程序。*/boolean jdbcCompliant();//------------------------- JDBC 4.1 -----------------------------------/**返回此驱动程序使用的所有Logger的父Logger。 这应该是距离根Logger最远的Logger,它仍然是该驱动程序使用的所有Logger的祖先。 配置此Logger将影响驱动程序生成的所有日志消息。 在最坏的情况下,它可能是根Logger。*/public Logger getParentLogger() throws SQLFeatureNotSupportedException;
}
Class.forName() 手动加载驱动

Class.forName()将对应的驱动类加载到内存中时,会执行驱动类中的static 静态代码快,创建一个驱动Driver的实例,注册到DriverManager中,供DriverManager使用。

//加载MySQL 数据库驱动
Class.forName("com.mysql.cj.jdbc.Driver");
DriverManager 源码分析
DriverManager 加载驱动

DriverManager 作为 Driver 的管理器,在首次被使用时,会执行其定义的static静态代码块,在静态代码快中,有一个 loadInitialDrivers() 静态方法,会首先加载配置在jdbc.drivers 系统属性内的驱动Driver。

    static {loadInitialDrivers();println("JDBC DriverManager initialized");}private static void loadInitialDrivers() {String drivers;//尝试从系统属性"jdbc.drivers"中获取驱动类try {drivers = AccessController.doPrivileged(new PrivilegedAction<String>() {public String run() {return System.getProperty("jdbc.drivers");}});} catch (Exception ex) {drivers = null;}//使用ServiceLoader 加载驱动程序AccessController.doPrivileged(new PrivilegedAction<Void>() {public Void run() {ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);Iterator<Driver> driversIterator = loadedDrivers.iterator();// 加载这些驱动程序,以便可以实例化它们。try{while(driversIterator.hasNext()) {driversIterator.next();}} catch(Throwable t) {// Do nothing}return null;}});println("DriverManager.initialize: jdbc.drivers = " + drivers);//jdbc.drivers 中的驱动处理if (drivers == null || drivers.equals("")) {return;}String[] driversList = drivers.split(":");println("number of Drivers:" + driversList.length);for (String aDriver : driversList) {try {println("DriverManager.Initialize: loading " + aDriver);Class.forName(aDriver, true,ClassLoader.getSystemClassLoader());} catch (Exception ex) {println("DriverManager.Initialize: load failed: " + ex);}}}
DriverManager 注册驱动
//同步注册   
public static synchronized void registerDriver(java.sql.Driver driver)throws SQLException {registerDriver(driver, null);}//CopyOnWriteArrayListprivate final static CopyOnWriteArrayList<DriverInfo> registeredDrivers = new CopyOnWriteArrayList<>();public static synchronized void registerDriver(java.sql.Driver driver,DriverAction da)throws SQLException {/* Register the driver if it has not already been added to our list */if(driver != null) {registeredDrivers.addIfAbsent(new DriverInfo(driver, da));} else {// This is for compatibility with the original DriverManagerthrow new NullPointerException();}println("registerDriver: " + driver);}
DriverManager 取消注册驱动
    @CallerSensitivepublic static synchronized void deregisterDriver(Driver driver)throws SQLException {if (driver == null) {return;}SecurityManager sec = System.getSecurityManager();if (sec != null) {sec.checkPermission(DEREGISTER_DRIVER_PERMISSION);}println("DriverManager.deregisterDriver: " + driver);DriverInfo aDriver = new DriverInfo(driver, null);//包含if(registeredDrivers.contains(aDriver)) {if (isDriverAllowed(driver, Reflection.getCallerClass())) {DriverInfo di = registeredDrivers.get(registeredDrivers.indexOf(aDriver));// If a DriverAction was specified, Call it to notify the// driver that it has been deregisteredif(di.action() != null) {di.action().deregister();}//移除registeredDrivers.remove(aDriver);} else {// If the caller does not have permission to load the driver then// throw a SecurityException.throw new SecurityException();}} else {println("    couldn't find driver to unload");}}
DriverManager 创建连接

通过遍历已加载的驱动程序,分别尝试连接指定的数据库,如果连接上则返回连接对象。

    @CallerSensitivepublic static Connection getConnection(String url)throws SQLException {java.util.Properties info = new java.util.Properties();return (getConnection(url, info, Reflection.getCallerClass()));}@CallerSensitivepublic static Connection getConnection(String url,java.util.Properties info) throws SQLException {return (getConnection(url, info, Reflection.getCallerClass()));}@CallerSensitivepublic static Connection getConnection(String url,String user, String password) throws SQLException {java.util.Properties info = new java.util.Properties();if (user != null) {info.put("user", user);}if (password != null) {info.put("password", password);}return (getConnection(url, info, Reflection.getCallerClass()));}private static Connection getConnection(String url, java.util.Properties info, Class<?> caller) throws SQLException {/*当callerCl为空时,检查应用程序的类加载器,以便可以从此处加载rt.jar外部的JDBC驱动程序类。*/ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;synchronized(DriverManager.class) {// synchronize loading of the correct classloader.if (callerCL == null) {callerCL = Thread.currentThread().getContextClassLoader();}}if(url == null) {throw new SQLException("The url cannot be null", "08001");}println("DriverManager.getConnection(\"" + url + "\")");SQLException reason = null;// 遍历每个驱动尝试连接指定的数据库地址for(DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if(isDriverAllowed(aDriver.driver, callerCL)) {try {println("    trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);if (con != null) {// Success!println("getConnection returning " + aDriver.driver.getClass().getName());return (con);}} catch (SQLException ex) {if (reason == null) {reason = ex;}}} else {println("    skipping: " + aDriver.getClass().getName());}}// if we got here nobody could connect.if (reason != null)    {println("getConnection failed: " + reason);throw reason;}println("getConnection: no suitable driver found for "+ url);throw new SQLException("No suitable driver found for "+ url, "08001");}

DataSource接口提供了另一种连接数据源的方法。 使用DataSource对象是连接数据源的首选方法

Wrapper

java.sql.Wrapper 是 JDBC 的接口,当相关实例实际上是代理类时,该接口提供检索委托实例的功能。

许多 JDBC 驱动程序实现使用包装器模式提供超越传统 JDBC API 的扩展功能,传统 JDBC API 是特定于数据源的。开发人员可能希望访问那些被包装(代理)为代表实际资源代理类实例的资源。

public interface Wrapper {<T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException;boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException;
}

T unwrap(java.lang.Class iface)

返回一个实现给定接口的对象,以允许访问非标准方法或代理未公开的标准方法。

如果接收者实现了该接口,那么结果是接收者或接收者代理。如果接收者是包装器且包装对象实现了该接口,那么结果是包装对象或包装对象的代理。否则,返回对该包装对象或该结果的代理进行递归调用的结果。如果接收者不是包装器且未实现该接口,则抛出 sqlexception。

boolean isWrapperFor(java.lang.Class<?> iface)

如果此方法实现了接口参数,或者直接或间接地对该对象进行了包装,则返回true。 否则返回false。

如果实现了接口,那么返回true,否则如果这是一个包装器,那么返回在包装对象上递归调用isWrapperFor的结果。

如果不实现接口并且不是包装器,则返回false。

unwrap 相比,此方法应作为一种低成本操作来实现,以便调用者可以使用此方法来避免可能失败的昂贵的 unwrap 调用。 如果此方法返回true,则使用相同参数调用unwrap应该会成功。

java.sql.Wrapper 主要有以下子接口:

  • DataSource:该工厂用于提供到此 DataSource 对象所表示的物理数据源的连接。
  • Connection:与特定数据库的连接(会话)。
  • DatabaseMetaData:关于数据库的整体综合信息。
  • ParameterMetaData:可用于获取关于 PreparedStatement 对象中每个参数标记的类型和属性信息的对象。
  • ResultSet:表示数据库结果集的数据表,通常通过执行查询数据库的语句生成。
  • ResultSetMetaData:可用于获取关于 ResultSet 对象中列的类型和属性信息的对象。
  • Statement:用于执行静态 SQL 语句并返回它所生成结果的对象。
  • CallableStatement:用于执行 SQL 存储过程的接口。
  • PreparedStatement:表示预编译的 SQL 语句的对象。
  • RowSet:该接口添加了对 JavaBeansTM 组件模型的 JDBC API 支持。
  • RowSetMetaData:该对象包含关于 RowSet 对象的列的信息。

image-20240106135039519

Connection

Connection 是Java应用程序和特定数据库之间的会话。 用来执行SQL语句,并在连接的上下文中返回结果。

public interface Connection  extends Wrapper, AutoCloseable {/**创建一个Statement对象,用于将SQL语句发送到数据库。 不带参数的SQL语句通常使用Statement对象执行。 如果多次执行同一条SQL语句,则使用PreparedStatement对象可能会更合适。
默认情况下,使用返回的Statement对象创建的结果集的类型为TYPE_FORWARD_ONLY,并发级别为CONCUR_READ_ONLY。 可以通过调用getHoldability()确定创建的结果集的可保存性。*/Statement createStatement() throws SQLException;/***/PreparedStatement prepareStatement(String sql)throws SQLException;CallableStatement prepareCall(String sql) throws SQLException;String nativeSQL(String sql) throws SQLException;void setAutoCommit(boolean autoCommit) throws SQLException;boolean getAutoCommit() throws SQLException;void commit() throws SQLException;void rollback() throws SQLException;void close() throws SQLException;boolean isClosed() throws SQLException;DatabaseMetaData getMetaData() throws SQLException;void setReadOnly(boolean readOnly) throws SQLException;boolean isReadOnly() throws SQLException;void setCatalog(String catalog) throws SQLException;String getCatalog() throws SQLException;/*** A constant indicating that transactions are not supported.*/int TRANSACTION_NONE             = 0;int TRANSACTION_READ_UNCOMMITTED = 1;int TRANSACTION_READ_COMMITTED   = 2;int TRANSACTION_REPEATABLE_READ  = 4;int TRANSACTION_SERIALIZABLE     = 8;void setTransactionIsolation(int level) throws SQLException;int getTransactionIsolation() throws SQLException;SQLWarning getWarnings() throws SQLException;void clearWarnings() throws SQLException;//--------------------------JDBC 2.0-----------------------------Statement createStatement(int resultSetType, int resultSetConcurrency)throws SQLException;PreparedStatement prepareStatement(String sql, int resultSetType,int resultSetConcurrency)throws SQLException;CallableStatement prepareCall(String sql, int resultSetType,int resultSetConcurrency) throws SQLException;java.util.Map<String,Class<?>> getTypeMap() throws SQLException;void setTypeMap(java.util.Map<String,Class<?>> map) throws SQLException;//--------------------------JDBC 3.0-----------------------------void setHoldability(int holdability) throws SQLException;int getHoldability() throws SQLException;Savepoint setSavepoint() throws SQLException;Savepoint setSavepoint(String name) throws SQLException;void rollback(Savepoint savepoint) throws SQLException;void releaseSavepoint(Savepoint savepoint) throws SQLException;Statement createStatement(int resultSetType, int resultSetConcurrency,int resultSetHoldability) throws SQLException;PreparedStatement prepareStatement(String sql, int resultSetType,int resultSetConcurrency, int resultSetHoldability)throws SQLException;CallableStatement prepareCall(String sql, int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws SQLException;PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)throws SQLException;PreparedStatement prepareStatement(String sql, int columnIndexes[])throws SQLException;PreparedStatement prepareStatement(String sql, String columnNames[])throws SQLException;Clob createClob() throws SQLException;Blob createBlob() throws SQLException;NClob createNClob() throws SQLException;SQLXML createSQLXML() throws SQLException;boolean isValid(int timeout) throws SQLException;void setClientInfo(String name, String value)throws SQLClientInfoException;void setClientInfo(Properties properties)throws SQLClientInfoException;String getClientInfo(String name)throws SQLException;Properties getClientInfo()throws SQLException;Array createArrayOf(String typeName, Object[] elements) throws
SQLException;Struct createStruct(String typeName, Object[] attributes)
throws SQLException;//--------------------------JDBC 4.1 -----------------------------void setSchema(String schema) throws SQLException;String getSchema() throws SQLException;void abort(Executor executor) throws SQLException;void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException;int getNetworkTimeout() throws SQLException;
}

Statement及子接口

PreparedStatement 表示预编译的SQL语句的对象,SQL语句已预编译并存储在PreparedStatement对象中。 然后可以使用该对象多次有效地执行该语句。

String sql = "insert into users values(?,?,?)";  
//可以通过setter来为每个参数赋值。pstmt.setBigDecimal(1, 153833.00)pstmt.setInt(2, 110592)
public interface Statement extends Wrapper, AutoCloseable {ResultSet executeQuery(String sql) throws SQLException;int executeUpdate(String sql) throws SQLException;void close() throws SQLException;//----------------------------------------------------------------------int getMaxFieldSize() throws SQLException;void setMaxFieldSize(int max) throws SQLException;int getMaxRows() throws SQLException;void setMaxRows(int max) throws SQLException;void setEscapeProcessing(boolean enable) throws SQLException;int getQueryTimeout() throws SQLException;void setQueryTimeout(int seconds) throws SQLException;void cancel() throws SQLException;SQLWarning getWarnings() throws SQLException;void clearWarnings() throws SQLException;void setCursorName(String name) throws SQLException;boolean execute(String sql) throws SQLException;ResultSet getResultSet() throws SQLException;int getUpdateCount() throws SQLException;boolean getMoreResults() throws SQLException;//--------------------------JDBC 2.0-----------------------------void setFetchDirection(int direction) throws SQLException;int getFetchDirection() throws SQLException;void setFetchSize(int rows) throws SQLException;int getFetchSize() throws SQLException;int getResultSetConcurrency() throws SQLException;int getResultSetType()  throws SQLException;/** 批次 加 sql */void addBatch( String sql ) throws SQLException;void clearBatch() throws SQLException;int[] executeBatch() throws SQLException;Connection getConnection()  throws SQLException;//--------------------------JDBC 3.0-----------------------------int CLOSE_CURRENT_RESULT = 1;int KEEP_CURRENT_RESULT = 2;int CLOSE_ALL_RESULTS = 3;int SUCCESS_NO_INFO = -2;int EXECUTE_FAILED = -3;int RETURN_GENERATED_KEYS = 1;int NO_GENERATED_KEYS = 2;boolean getMoreResults(int current) throws SQLException;ResultSet getGeneratedKeys() throws SQLException;int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException;int executeUpdate(String sql, int columnIndexes[]) throws SQLException;int executeUpdate(String sql, String columnNames[]) throws SQLException;boolean execute(String sql, int autoGeneratedKeys) throws SQLException;boolean execute(String sql, int columnIndexes[]) throws SQLException;boolean execute(String sql, String columnNames[]) throws SQLException;int getResultSetHoldability() throws SQLException;boolean isClosed() throws SQLException;void setPoolable(boolean poolable)throws SQLException;boolean isPoolable()throws SQLException;//--------------------------JDBC 4.1 -----------------------------public void closeOnCompletion() throws SQLException;public boolean isCloseOnCompletion() throws SQLException;//--------------------------JDBC 4.2 -----------------------------default long getLargeUpdateCount() throws SQLException {throw new UnsupportedOperationException("getLargeUpdateCount not implemented");}default void setLargeMaxRows(long max) throws SQLException {throw new UnsupportedOperationException("setLargeMaxRows not implemented");}default long getLargeMaxRows() throws SQLException {return 0;}default long[] executeLargeBatch() throws SQLException {throw new UnsupportedOperationException("executeLargeBatch not implemented");}default long executeLargeUpdate(String sql) throws SQLException {throw new UnsupportedOperationException("executeLargeUpdate not implemented");}default long executeLargeUpdate(String sql, int autoGeneratedKeys)throws SQLException {throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");}default long executeLargeUpdate(String sql, int columnIndexes[]) throws SQLException {throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");}default long executeLargeUpdate(String sql, String columnNames[])throws SQLException {throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");}
}

public interface PreparedStatement extends Statement {ResultSet executeQuery() throws SQLException;int executeUpdate() throws SQLException;/**  下面是各种数据类型的设置 */void setNull(int parameterIndex, int sqlType) throws SQLException;void setXXXX(int parameterIndex, <Type> x) throws SQLException;void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)throws SQLException;@Deprecatedvoid setUnicodeStream(int parameterIndex, java.io.InputStream x,int length) throws SQLException;void setBinaryStream(int parameterIndex, java.io.InputStream x,int length) throws SQLException;void clearParameters() throws SQLException;//----------------------------------------------------------------------// Advanced features:void setObject(int parameterIndex, Object x, int targetSqlType)throws SQLException;void setObject(int parameterIndex, Object x) throws SQLException;boolean execute() throws SQLException;//--------------------------JDBC 2.0-----------------------------/** 把当前参数 的设置 加到批次 */void addBatch() throws SQLException;void setYYY(int parameterIndex, YYY y) throws SQLException;//------------------------- JDBC 3.0 -----------------------------------void setURL(int parameterIndex, java.net.URL x) throws SQLException;ParameterMetaData getParameterMetaData() throws SQLException;//------------------------- JDBC 4.0 -----------------------------------/** 新增的数据类型*/void setRowId(int parameterIndex, RowId x) throws SQLException;void setNString(int parameterIndex, String value) throws SQLException;void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException;//------------------------- JDBC 4.2 -----------------------------------default void setObject(int parameterIndex, Object x, SQLType targetSqlType,int scaleOrLength) throws SQLException {throw new SQLFeatureNotSupportedException("setObject not implemented");}default void setObject(int parameterIndex, Object x, SQLType targetSqlType)throws SQLException {throw new SQLFeatureNotSupportedException("setObject not implemented");}default long executeLargeUpdate() throws SQLException {throw new UnsupportedOperationException("executeLargeUpdate not implemented");}
}

使用 Statement 对象进行批处理更新

StatementPreparedStatementCallableStatement 对象具有与其关联的命令列表。 该列表在创建时与 Statement 对象相关联,初始是空的。 您可以使用addBatch方法将SQL命令添加到此列表,并使用clearBatch方法将其清空。 完成将语句添加到列表后,请调用executeBatch方法将其全部发送到数据库以作为一个单元或批处理执行。

 public static void main(String[] args) throws SQLException {batchUpdate();}/*** 使用 Statement 对象进行批处理更新*/private static void batchUpdate() {//Step 1: 创建 Connection 对象try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT", "root", "root");// Step 2:使用 connection 创建 statement 对象Statement statement = connection.createStatement()) {connection.setAutoCommit(false);statement.addBatch("INSERT INTO Users VALUES (1, 'XXX', 'xxx@qq.com', 'China', '1234');");statement.addBatch("INSERT INTO Users VALUES (2, 'YYY', 'yyy@qq.com', 'China', '1235');");//批处理int[] updateCounts = statement.executeBatch();System.out.println(Arrays.toString(updateCounts));connection.commit();} catch (BatchUpdateException batchUpdateException) {printBatchUpdateException(batchUpdateException);} catch (SQLException e) {printSQLException(e);}}
进行参数化的批量更新
private static void parameterizedBatchUpdate() {String INSERT_USERS_SQL = "INSERT INTO users" + "  (id, name, email, country, password) VALUES " +" (?, ?, ?, ?, ?);";try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT", "root", "root");PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL)) {connection.setAutoCommit(false);preparedStatement.setInt(1, 8);preparedStatement.setString(2, "XXX");preparedStatement.setString(3, "xxx@qq.com");preparedStatement.setString(4, "China");preparedStatement.setString(5, "1");preparedStatement.addBatch();preparedStatement.setInt(1, 9);preparedStatement.setString(2, "YYYY");preparedStatement.setString(3, "yyyy@qq.com");preparedStatement.setString(4, "China");preparedStatement.setString(5, "2");preparedStatement.addBatch();preparedStatement.setInt(1, 10);preparedStatement.setString(2, "ZZZZ");preparedStatement.setString(3, "zzzz@qq.com");preparedStatement.setString(4, "China");preparedStatement.setString(5, "3");preparedStatement.addBatch();preparedStatement.setInt(1, 11);preparedStatement.setString(2, "DDDD");preparedStatement.setString(3, "dddd.com");preparedStatement.setString(4, "China");preparedStatement.setString(5, "4");preparedStatement.addBatch();int[] updateCounts = preparedStatement.executeBatch();System.out.println(Arrays.toString(updateCounts));connection.commit();connection.setAutoCommit(true);} catch (BatchUpdateException batchUpdateException) {printBatchUpdateException(batchUpdateException);} catch (SQLException e) {printSQLException(e);}}

ResultSet

ResultSet 接口提供了用于检索和处理已获得结果集的方法,并且ResultSet对象具有不同的功能和特性。 这些特性是type(类型), concurrency(并发性), cursor holdability(游标可保持性)。

ResultSet 对象维护一个游标,该游标指向其当前数据行。 next 方法将光标移动到下一行,当ResultSet对象中没有更多行时它返回false,因此可以在while循环中使用它来迭代结果集。

默认的 ResultSet 对象是不可更新的,并且只有仅向前移动的光标。 因此,您只能从第一行到最后一行迭代一次。

可以生成可滚动可更新的ResultSet对象。 下面的代码片段(其中con是有效的Connection对象)说明了如何创建一个可滚动且对其他更新不敏感并且可更新的结果集。

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);ResultSet rs = stmt.executeQuery("SELECT a, b FROM test");

ResultSet 接口提供了用于从当前行检索列值的getter方法(getBoolean,getLong等)。 可以使用列的索引号列的名称来检索值。 通常,使用列索,列索引编号从1开始编号。为了实现最大的可移植性,应按从左到右的顺序读取每一行中的结果集列,并且每一列只能读取一次

对于getter方法,JDBC驱动程序尝试将基础数据转换为getter方法中指定的Java类型,并返回合适的Java值。 JDBC规范具有一个表,该表显示了ResultSet getter方法可以使用的从SQL类型Java类型的映射。

用作getter方法的列名不区分大小写。 当使用列名调用getter方法并且多个列具有相同的名称时,将返回第一个匹配列的值。 对于在查询中未明确命名的列,最好使用列号。 如果使用了列名,则应注意确保它们的唯一,这可以通过SQL AS子句来确保。

JDBC 2.0 API中,向该接口添加了一组更新程序方法。 有关getter方法的参数的注释也适用于updater方法的参数。

更新方法有两种使用方式:

1、更新当前行中的列值:在可滚动ResultSet对象中,光标可以前后移动,移动到绝对位置或相对于当前行的位置

rs.absolute(6); // 移动光标到 rs 的第6行
rs.updateString("NAME", "xxx"); // 更新 NAME 列的值为 xxx
rs.updateRow(); // 更新当前数据源 rs 中的第6行操作

2、将列值插入到插入行中:可更新的ResultSet对象具有与其关联的特殊行,该行用作构建要插入的行的暂存区。

       rs.moveToInsertRow(); // 移动游标到插入行rs.updateString(1, "xxx"); // 更新插入行第一列的值为 xxxrs.updateInt(2,3); // 更新第二列的值为 3rs.updateBoolean(3, true); // 更新第三列的值为 truers.insertRow();rs.moveToCurrentRow();

ResultSet 类型

ResultSet 对象的类型在两个方面确定其功能级别:游标的操作方式以及ResultSet对象如何反映对基础数据源进行的并发更改。

游标的操作方式:

  • TYPE_FORWARD_ONLY
    结果集无法滚动,它的光标只能从第一行之前移到最后一行之后。 结果集中包含的行取决于基础数据库如何生成的结果。 即,它包含在执行查询时或在检索行时满足查询条件的行。

  • TYPE_SCROLL_INSENSITIVE
    结果集可以滚动, 它的光标可以相对于当前位置向前和向后移动,并且可以移动到绝对位置。 结果集在打开时对基础数据源所做的更改不敏感。 它包含在执行查询时或在检索行时满足查询条件的行。

  • TYPE_SCROLL_SENSITIVE
    结果可以滚动,它的光标可以相对于当前位置向前和向后移动,并且可以移动到绝对位置。 结果集反映在结果集保持打开状态时对基础数据源所做的更改

ResultSet 并发性:

ResultSet 对象的并发性确定了支持什么级别的更新功能。

  • CONCUR_READ_ONLY:无法使用ResultSet接口更新ResultSet对象。
  • CONCUR_UPDATABLE:可以使用ResultSet接口更新ResultSet对象。

Cursor Holdability(游标可保持性)

调用方法Connection.commit可以关闭在当前事务期间创建的ResultSet对象。 但是,在某些情况下,这可能不是所需的行为。 ResultSet属性的可保留性使应用程序可以控制在调用提交时是否关闭ResultSet对象(光标)。

可以将以下ResultSet常量提供给Connection方法的createStatementprepareStatementprepareCall

  • HOLD_CURSORS_OVER_COMMIT: ResultSet游标未关闭,它是可保持的,调用方法commit时,它们保持打开状态。 如果您的应用程序主要使用只读的ResultSet对象,则可保持游标可能是理想的选择。
  • CLOSE_CURSORS_AT_COMMIT: 调用commit方法时,将关闭ResultSet对象(光标)。 调用此方法时关闭游标可以提高某些应用程序的性能。

ResultSetMetaData

ResultSetMetaData 对象用于收集ResultSet的所有信息,例如列的类型和属性列数的名称,列的数据类型等。简单来说,它用于收集 ResultSet 的信息。

ResultSetMetaData 封装了描述 ResultSet 对象的数据,内部提供了大量的方法来获取 ResultSet 的信息

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM test");
ResultSetMetaData rsmd = rs.getMetaData();
//获取有多少列
int numberOfColumns = rsmd.getColumnCount();
boolean b = rsmd.isSearchable(1);

常用方法

方法描述
int getColumnCount() throws SQLException返回 ResultSet 对象列的数量
String getColumnName(int column) throws SQLException根据指定的索引获取列名
int getColumnType(int column) throws SQLException根据指定索引检索指定列的SQL类型
String getTableName(int column) throws SQLException根据列索引获取表名
String getSchemaName(int column)获取指定列的表的结构
int getScale(int column) throws SQLException获取指定列的小数点右边的位数。 对于不适用小数位数的数据类型,返回0。
int getPrecision(int column) throws SQLException获取指定列的指定列大小。

DatabaseMetaData

DatabaseMetaData 接口提供了获取数据库元数据的方法,例如数据库名称,数据库版本,驱动程序名称,表总数,视图总数等。

数据库实现

数据库的实现以mysql为例。

Driver实现

Class.forName("com.mysql.jdbc.Driver") 被执行时,com.mysql.jdbc.Driver类就会被加载,同时也在静态代码块中完成了向DriverManager的注册

public class Driver extends NonRegisteringDriver implements java.sql.Driver {public Driver() throws SQLException {}static {try {DriverManager.registerDriver(new Driver());} catch (SQLException var1) {throw new RuntimeException("Can't register driver!");}}
}

具体实现在类NonRegisteringDriver中。


public class NonRegisteringDriver implements Driver {//System.getProperty("os.name");public static String getOSName() {return Constants.OS_NAME;}//System.getProperty("os.arch");public static String getPlatform() {return Constants.OS_ARCH;}static int getMajorVersionInternal() {return StringUtils.safeIntParse("8");}static int getMinorVersionInternal() {return StringUtils.safeIntParse("0");}public NonRegisteringDriver() throws SQLException {}public boolean acceptsURL(String url) throws SQLException {try {//helper类return ConnectionUrl.acceptsUrl(url);} catch (CJException var3) {throw SQLExceptionsMapping.translateException(var3);}}public Connection connect(String url, Properties info) throws SQLException {try {try {if (!ConnectionUrl.acceptsUrl(url)) {return null;} else {ConnectionUrl conStr = ConnectionUrl.getConnectionUrlInstance(url, info);switch (conStr.getType()) {//单实例case SINGLE_CONNECTION:return ConnectionImpl.getInstance(conStr.getMainHost());case LOADBALANCE_CONNECTION:return LoadBalancedConnectionProxy.createProxyInstance((LoadbalanceConnectionUrl)conStr);case FAILOVER_CONNECTION:return FailoverConnectionProxy.createProxyInstance(conStr);//复制case REPLICATION_CONNECTION:return ReplicationConnectionProxy.createProxyInstance((ReplicationConnectionUrl)conStr);default:return null;}}} catch (UnsupportedConnectionStringException var5) {return null;} catch (CJException var6) {throw (UnableToConnectException)ExceptionFactory.createException(UnableToConnectException.class, Messages.getString("NonRegisteringDriver.17", new Object[]{var6.toString()}), var6);}} catch (CJException var7) {throw SQLExceptionsMapping.translateException(var7);}}public int getMajorVersion() {return getMajorVersionInternal();}public int getMinorVersion() {return getMinorVersionInternal();}public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {try {String host = "";String port = "";String database = "";String user = "";String password = "";if (!StringUtils.isNullOrEmpty(url)) {//解析urlConnectionUrl connStr = ConnectionUrl.getConnectionUrlInstance(url, info);if (connStr.getType() == Type.SINGLE_CONNECTION) {HostInfo hostInfo = connStr.getMainHost();info = hostInfo.exposeAsProperties();}}if (info != null) {host = info.getProperty(PropertyKey.HOST.getKeyName());port = info.getProperty(PropertyKey.PORT.getKeyName());database = info.getProperty(PropertyKey.DBNAME.getKeyName());user = info.getProperty(PropertyKey.USER.getKeyName());password = info.getProperty(PropertyKey.PASSWORD.getKeyName());}DriverPropertyInfo hostProp = new DriverPropertyInfo(PropertyKey.HOST.getKeyName(), host);hostProp.required = true;hostProp.description = Messages.getString("NonRegisteringDriver.3");DriverPropertyInfo portProp = new DriverPropertyInfo(PropertyKey.PORT.getKeyName(), port);portProp.required = false;portProp.description = Messages.getString("NonRegisteringDriver.7");DriverPropertyInfo dbProp = new DriverPropertyInfo(PropertyKey.DBNAME.getKeyName(), database);dbProp.required = false;dbProp.description = Messages.getString("NonRegisteringDriver.10");DriverPropertyInfo userProp = new DriverPropertyInfo(PropertyKey.USER.getKeyName(), user);userProp.required = true;userProp.description = Messages.getString("NonRegisteringDriver.13");DriverPropertyInfo passwordProp = new DriverPropertyInfo(PropertyKey.PASSWORD.getKeyName(), password);passwordProp.required = true;passwordProp.description = Messages.getString("NonRegisteringDriver.16");//5个关键属性。DriverPropertyInfo[] dpi = (new JdbcPropertySetImpl()).exposeAsDriverPropertyInfo(info, 5);dpi[0] = hostProp;dpi[1] = portProp;dpi[2] = dbProp;dpi[3] = userProp;dpi[4] = passwordProp;return dpi;} catch (CJException var15) {throw SQLExceptionsMapping.translateException(var15);}}public boolean jdbcCompliant() {return false;}public Logger getParentLogger() throws SQLFeatureNotSupportedException {throw new SQLFeatureNotSupportedException();}static {try {Class.forName(AbandonedConnectionCleanupThread.class.getName());} catch (ClassNotFoundException var1) {}}
}

ConnectionUrl

附录

参考

java.sql包API

PreparedStatement 性能

数据库解析SQL字符串并为其创建查询计划需要花费时间。 查询计划则是对数据库如何以最有效的方式执行查询的分析。

如果为每个查询或对数据库的更新提交新的完整SQL语句,则数据库必须解析SQL,并为查询创建查询计划。 通过重用现有的 PreparedStatement,您可以将SQL解析和查询计划复用于后续查询。 通过减少每次执行的解析和查询计划开销,这可以加快查询的执行速度。

PreparedStatement 的复用有以下两个方面:

  • JDBC驱动程序重用 PreparedStatement。
  • 数据库重用 PreparedStatement。

首先,JDBC驱动程序可以在内部缓存PreparedStatement对象,从而可以重用PreparedStatement对象。 这样可以节省少许PreparedStatement创建时间。

其次,缓存的解析和查询计划可能会使用相同的数据库跨Java应用程序(例如集群中的应用程序服务器)重用。

相关文章:

jdbc源码研究

JDBC介绍 JDBC&#xff08;Java Data Base Connectivity,java数据库连接&#xff09;是一种用于执行SQL语句的Java API&#xff0c;可以为多种关系数据库提供统一访问&#xff0c;它由一组用Java语言编写的类和接口组成。 开发者不必为每家数据通信协议的不同而疲于奔命&#…...

挠性及刚挠结合印制电路技术

1.1挠性印制电路板概述 20世纪70年代末期&#xff0c;以日本厂商为主导&#xff0c;逐渐将挠性印制电路板(flexible printedcircuit board&#xff0c;FPCB&#xff0c;简称为FPC)广泛应用于计算机、照相机、打印机、汽车音响、硬盘驱动器等电子信息产品中。20世纪90年代初期&…...

Python+OpenGL绘制3D模型(七)制作3dsmax导出插件

系列文章 一、逆向工程 Sketchup 逆向工程&#xff08;一&#xff09;破解.skp文件数据结构 Sketchup 逆向工程&#xff08;二&#xff09;分析三维模型数据结构 Sketchup 逆向工程&#xff08;三&#xff09;软件逆向工程从何处入手 Sketchup 逆向工程&#xff08;四&#xf…...

MediaPipeUnityPlugin Win10环境搭建(22年3月的记录,新版本已完全不同,这里只做记录)

https://github.com/homuler/MediaPipeUnityPlugin You cannot build libraries for Android with the following steps. 1、安装msys2配置系统环境变量Path添加 C:\msys64\usr\bin 执行 pacman -Su 执行 pacman -S git patch unzip 2、安装Python3.9.10 勾选系统环境变量 …...

Nginx - location块中的alias和try_files重定向

nginx.conf片段&#xff1a; location /logo/general/ {autoindex_localtime on;alias /opt/config/;try_files /logo/logo.png /www/html/logo.png 404;} 意为&#xff1a;访问/logo/general/地址时&#xff0c; 如&#xff1a;访问http://127.0.0.1/logo/general/logo.png…...

二刷Laravel 教程(用户模型)总结Ⅲ

一、数据库迁移 当我们运行迁移时&#xff0c;up 方法会被调用&#xff1b;&#xff08;创建表&#xff09; 当我们回滚迁移时&#xff0c;down 方法会被调用。&#xff08;删除表&#xff09; public function up() { //create 方法会接收两个参数&#xff1a;一个是数据…...

安装PyTorch及环境配置(应用于Python上的YOLO)

这个基本都是Bilibili网站里面叫“小手丫子”up的视频教程&#xff0c;此前自己需要装了好几次又卸载了好几次&#xff0c;现在根据视频教学整理出来自己所理解的文档。 注意事项 1.安装的pycharm版本和anaconda版本无要求。 2.运行pycharm尽量以管理员身份运行。 3.Cuda是独…...

【194】PostgreSQL 14.5 编写SQL从身份证号中查找性别,并且更新性别字段。

假设有一张用户表 t_user &#xff0c;该表设计如下&#xff1a; id: character varying 主键 name: character varying 姓名 idcard: character varying 身份证号 gender: smallint 性别&#xff0c;女是0&#xff0c;男是1根据身份证号查找所有未填写…...

微服务管家:NestJS 如何使用服务发现 Consul 实现高效的微服务节点管理

前言 在微服务架构中&#xff0c;服务发现是一项基础且关键的功能&#xff0c;它允许服务实例在网络中被动态发现。Consul 是一种服务网格解决方案&#xff0c;提供了服务发现、运行状况检查&#xff0c;过去和现代应用程序的连接等功能。 本教程将向您展示如何在 NestJS 框架…...

Baumer工业相机堡盟工业相机如何联合NEOAPI SDK和OpenCV实现相机图像转换为Mat图像格式(C++)

Baumer工业相机堡盟工业相机如何通过NEOAPI SDK实现相机掉线自动重连&#xff08;C&#xff09; Baumer工业相机Baumer工业相机的图像转换为OpenCV的Mat图像的技术背景在NEOAPI SDK里实现相机图像转换为Mat图像格式联合OpenCV实现相机图像转换为Mat图像格式测试演示图 工业相机…...

铁塔基站数字化管理监测解决方案

截至2023年10月&#xff0c;我国5G基站总数达321.5万个&#xff0c;占全国通信基站总数的28.1%。然而&#xff0c;随着5G基站数量的快速增长&#xff0c;基站的能耗问题也逐渐日益凸显&#xff0c;基站的用电给运营商带来了巨大的电费开支压力&#xff0c;降低5G基站的能耗成为…...

如何使用Python3 Boto3删除AWS CloudFormation的栈(Stacks)

文章目录 小结问题及解决有关Json文件的输入和输出使用Python3及正则表达式查找字符串包含某个子字符串使用Python3 Boto3删除AWS CloudFormation的栈&#xff08;Stacks&#xff09; 参考 小结 本文记录了使用Python3的Boto3包删除AWS CloudFormation的栈&#xff08;Stacks&…...

差分约束算法

差分约束 差分约束系统包含 m m m个涉及 n n n个变量的差额限制条件&#xff0c;这些差额限制条件每个都是形式为 x i − x j ≤ b ∈ [ 1 , m ] x_i-x_j\leq b_{\in[1,m]} xi​−xj​≤b∈[1,m]​的简单线性不等式。 通常我们要求解出一组可行解。 最短路差分约束 如果我们…...

彻底解决vue-video-player播放视频有黑边

需求 最近需要接入海康视频摄像头&#xff0c;然后把视频的画面接入到自己的网站系统中。以前对接过rtsp固定IP的显示视频&#xff0c;这次的不一样&#xff0c;没有了固定IP。海康的解决办法是&#xff0c;摄像头通过配置服务器到萤石云平台&#xff0c;然后购买企业版账号和…...

区域负责人常用的ChatGPT通用提示词模板

区域市场分析&#xff1a;如何分析区域市场的特点、竞争态势和客户需求&#xff1f; 区域销售策略制定&#xff1a;如何制定针对区域市场的销售策略&#xff0c;包括产品定位、价格策略、渠道策略等&#xff1f; 区域销售目标设定&#xff1a;如何设定明确的区域销售目标&…...

Java Spring boot 可變參數,以及弊端

function中 不固定的參數 public boolean sendEmail(String manFrom, String manTo,String manCc, String subject, String... msg); 必須是最後一個參數&#xff0c;傳值時可以多個。 sendEmail(“a.gmail”,"b.gmail","c.gmail","subject",…...

机器视觉系统选型-线阵工业相机选型

线阵相机特点&#xff1a; 1.线阵相机使用的线扫描传感器通常只有一行感光单元&#xff08;少数彩色线阵使用三行感光单元的传感器&#xff09; 2.线阵相机每次只采集一行图像&#xff1b; 3.线阵相机每次只输出一行图像&#xff1b; 4.与传统的面阵相机相比&#xff0c;面阵扫…...

单机开机无感全自动进入B\S架构系统

单机开机无感全自动进入B\S架构系统 标题&#xff1a;单机用jar包启动项目bat&#xff08;批处理&#xff09;不弹黑窗口&#xff0c;并设置开机自启&#xff0c;打开浏览器&#xff0c;访问系统。引言&#xff1a;在实际工作中&#xff0c;遇到单机部署的情况&#xff0c;如今…...

大一,如何成为一名fpga工程师?

​ 1、数电&#xff08;必须掌握的基础&#xff09;&#xff0c;然后进阶学模电&#xff08;选学&#xff09;&#xff0c; 2、掌握HDL&#xff08;HDLverilogVHDL&#xff09;可以选择verilog或者VHDL&#xff0c;建议verilog就行。 3、掌握FPGA设计流程/原理&#xff08;推…...

MyBatisPlus学习三:Service接口、代码生成器

学习教程 黑马程序员最新MybatisPlus全套视频教程&#xff0c;4小时快速精通mybatis-plus框架 Service接口 简介 在MyBatis-Plus框架中&#xff0c;Service接口的作用是为实体类提供一系列的通用CRUD&#xff08;增删改查&#xff09;操作方法。通常情况下&#xff0c;Servi…...

产品经理如何选择城市?

年底&#xff0c;全国性的人口大迁徙即将开始。选择城市&#xff0c;堪称年轻人的“二次投胎”&#xff0c;族望留原籍&#xff0c;家贫走他乡。 古人在选择城市时&#xff0c;主要的考量因素是家族势力&#xff0c;这一点放在当代&#xff0c;大致也成立&#xff0c;如果在老…...

再谈“敏捷”与“瀑布”在产品开发过程中的反思

作为一家专注于软件开发的公司《智创有术》&#xff0c;我们致力于为客户提供创新、高效和可靠的解决方案。通过多年的经验和专业知识&#xff0c;我们已经在行业内建立了良好的声誉&#xff0c;并赢得了客户的信任和支持。 支持各种源码&#xff0c;网站搭建&#xff0c;APP&a…...

设计模式② :交给子类

文章目录 一、前言二、Template Method 模式1. 介绍2. 应用3. 总结 三、Factory Method 模式1. 介绍2. 应用3. 总结 参考内容 一、前言 有时候不想动脑子&#xff0c;就懒得看源码又不像浪费时间所以会看看书&#xff0c;但是又记不住&#xff0c;所以决定开始写"抄书&qu…...

Hive 源码

hive 编译 issue Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.5.1.1:run (default) on project hive-standalone-metastore: Error resolving artifact: com.google.protobuf:protoc:2.5.0: The following artifacts could not be resolved: com.goog…...

调整几行代码,接口吞吐提升 10 倍,性能调优妙啊!

景 分析过程 总结 背景 公司的一个ToB系统,因为客户使用的也不多,没啥并发要求,就一直没有经过压测。这两天来了一个“大客户”,对并发量提出了要求:核心接口与几个重点使用场景单节点吞吐量要满足最低500/s的要求。 当时一想,500/s吞吐量还不简单。Tomcat按照100个线程…...

MACOS Atrust服务异常

MAC版Atrust服务异常 点击进入办公后出现提示其一&#xff1a; 核心服务未启动&#xff0c;部分功能存在异常&#xff0c;确定重新启动吗&#xff1f; 可能的原因&#xff1a; 1.上次已完全退出客户端 2.核心服务被其他程序优化禁用 点击重新启动后&#xff0c;出现提示&#x…...

LLM大语言模型(四):在ChatGLM3-6B中使用langchain

目录 背景准备工作工具添加LangChain 已实现工具Calculator、Weather Tool配置 自定义工具自定义kuakuawo Agent 多工具使用参考 背景 LangChain是一个用于开发由语言模型驱动的应用程序的框架。它使应用程序能够: 具有上下文意识&#xff1a;将语言模型与上下文源(提示指令&…...

Dubbo入门介绍和实战

1. 引言 Dubbo是一款开源的高性能、轻量级的Java RPC&#xff08;远程过程调用&#xff09;框架&#xff0c;旨在解决分布式服务之间的通信问题。本文将介绍Dubbo的基础概念、核心特性以及使用场景&#xff0c;包括实际示例演示。 2. 什么是Dubbo&#xff1f; Dubbo是阿里巴…...

如何实现无人机识别功能

无人机识别算法可以基于不同的传感器和技术&#xff0c;结合多种方法进行实现。以下是一些常见的无人机识别算法和技术&#xff1a; 视觉识别&#xff1a; 图像处理&#xff1a; 使用计算机视觉技术对无人机图像进行处理&#xff0c;包括特征提取、目标检测和跟踪等。深度学习&…...

Python学习笔记(四)流程控制方法

流程控制有三种方法&#xff1a;分支、循环、跳出 流程的控制通过布尔值来实现&#xff0c;分支和循环都需要对一定的条件进行判断&#xff0c;根据判断结果&#xff08;布尔值&#xff09;决定下一步要做什么 布尔值通过比较运算符、逻辑运算符来进行判断是True还是False 不…...

网站建设广州公司/网站建站公司

本节摘要&#xff1a;之前对JSON做了一次简单的介绍&#xff0c;并把JSON和XML做了一个简单的比较&#xff1b;那么&#xff0c;我就在想&#xff0c;如果是一个json格式的字符串传到后台&#xff0c;需要怎么对其处理&#xff1f;如果前台页面需要后台返回的是一个json的字符串…...

wordpress视频网站采集器/沈阳关键词优化价格

goroutine和channel结合使用案例 应用案例 请完成goroutine和channel协同工作的案例&#xff0c;具体要求&#xff1a; 1&#xff09;开启一个writeData协程&#xff0c;向管道intChan中写入50个整数.2&#xff09;开启一个readData协程&#xff0c;从管道intChan中读取writeD…...

织梦转wordpress插件下载地址/关键词优化排名要多少钱

文章目录前言一、STM32端二、K210测试结果前言 想用STM32通过串口给K210发数据&#xff0c;并在屏幕上显示&#xff0c;看了好几篇博客&#xff0c;终于搞通了&#xff0c;大家感兴趣也可以看看。 K210学习笔记(一) K210与STM32串口通信相关 接线&#xff0c;STM32的串口引脚比…...

学校网站 源码/设计模板网站

---------------------------------备考概括---------------------------------问&#xff1a;备考过程中最重要的是什么&#xff1f;答&#xff1a;要说最重要的&#xff0c;无非是态度&#xff0c;尤其是学会自省&#xff0c;它是一成不变的&#xff0c;对每个人都有效果的。…...

四川建设厅网站施工员证查询/seo和sem的区别是什么?

&#xff08;二&#xff09;内存 内存地址 区分三种不同的地址&#xff1a;1.逻辑地址&#xff1a;机器语言指令中指定操作书或指令的地址&#xff0c;由段和偏移量构成 2.线性/虚拟地址&#xff1a;应用程序的地址 3.物理地址&#xff1a;在内存芯片上的寻址地址   逻辑地址…...

学校文化建设的网站/网络营销战略

2019独角兽企业重金招聘Python工程师标准>>> 性能与可伸缩性 性能包括&#xff1a;服务时间、延迟时间、吞吐率、效率、容量等 可伸缩性&#xff1a;当增加计算资源时&#xff08;例如CPU、内存、存储容量或I/O带宽&#xff09;&#xff0c;程序的吞吐量或者处理能力…...