Get the Maximum Table Name Length allowed in a Database in Java
Description
The following code shows how to get the Maximum Table Name Length allowed in a Database.
Example
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.util.Arrays;
//from www . j a va 2 s . co m
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = getConnection();
DatabaseMetaData dbmd = connection.getMetaData();
// Get max table name length
int length = dbmd.getMaxTableNameLength();
System.out.println(length);
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}