Java中我怎么知道数据库是否支持可更新的结果集?
package org.nhooo.example.jdbc; import java.sql.*; public class SupportUpdatableResultSet { private static final String URL = "jdbc:mysql://localhost/nhooo"; private static final String USERNAME = "root"; private static final String PASSWORD = ""; public static void main(String[] args) { try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { DatabaseMetaData meta = connection.getMetaData(); boolean updatable = meta.supportsResultSetConcurrency( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); System.out.println("Updatable ResultSet = " + updatable); } catch (SQLException e) { e.printStackTrace(); } } }
上面的代码片段的结果:
Updatable ResultSet = true
Maven依赖
<!-- https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>