Get database maximum table name length in Java
Description
The following code shows how to get database maximum table name length.
Example
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
/*from w ww . j a v a2 s . c om*/
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = getConnection();
DatabaseMetaData metadata = connection.getMetaData();
int maxLength = metadata.getMaxTableNameLength();
System.out.println("Max Table Name Length = " + maxLength);
connection.close();
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}