Here you can find the source of getLength(String format, String columnTypeName)
public static int getLength(String format, String columnTypeName) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.SQLException; public class Main { public static int getLength(String format, String columnTypeName) throws SQLException { //format = format.replace("%", "%1$"); String col = columnTypeName.substring(0, 3); try {//from w w w . ja va2 s .c o m if (col.equals("TIM") || col.equals("DAT")) { return String.format(format, new java.sql.Timestamp(0)).length(); } else if (col.equals("NUM") || col.equals("DEC")) { return String.format(format, new java.math.BigDecimal(0)).length(); } else if (col.equals("VAR") || col.equals("CHA") || col.equals("STR")) { return String.format(format, " ").length(); } else if (col.equals("INT") || col.equals("SMA") || col.equals("BIN") || col.equals("POS") || col.equals("SIG") || col.equals("NAT") || col.equals("PLS")) { return String.format(format, 0).length(); } else if (col.equals("DOU") || col.equals("FLO")) { return String.format(format, 0.0).length(); } else if (col.equals("REA")) { return String.format(format, 0.0f).length(); } else if (col.equals("BOO") || col.equals("")) { return 4; } else { throw new SQLException( "Can't format the SQL datatype: (" + col + ") " + columnTypeName + " format :" + format); } /* * Oracle data types currently not handled.... case "NCH": //NCHAR * case "NVA": //NVARCHAR return String.format(format, new * oracle.sql.NString )).length(); case "ROW": //ROWID, case "URO": * //UROWID return String.format(format, new * oracle.sql.ROWID()).length(); case "INT": //INTERVAL YEAR TO * MONTH, INTERVAL DAY TO SECOND -- conflict */ } catch (Exception e) { System.err.println( "Failed to format the SQL datatype: (" + col + ") " + columnTypeName + " format :" + format); throw new SQLException(e); } } }