Java中如何获得数据库的最大表名长度?
package org.nhooo.example.jdbc;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
public class MaximumTableNameLength {
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 metadata = connection.getMetaData();
// 获取数据库表名最大长度的信息
int maxLength = metadata.getMaxTableNameLength();
System.out.println("Max Table Name Length = " + maxLength);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
上面的代码片段的结果是:
Max Table Name Length = 64
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>
以上是 Java中如何获得数据库的最大表名长度? 的全部内容, 来源链接: utcz.com/z/321420.html