/**
*
* @param con
* @param synonym
* @param columnName
* @return
* @throws SQLException
*/
/**
* @param con
* @param synonym
* @param columnName
* @return
* @throws SQLException
*/
public static int getColumnType(ISQLConnection con, ITableInfo ti, String columnName) throws SQLException {
int result = -1;
if (ti != null) {
TableColumnInfo[] tciArr = con.getSQLMetaData().getColumnInfo(ti);
for (int i = 0; i < tciArr.length; i++) {
if (tciArr[i].getColumnName().equalsIgnoreCase(columnName)) {
result = tciArr[i].getDataType();
break;
}
}
}
return result;
}
public static int[] getColumnTypes(ISQLConnection con, ITableInfo ti, String[] colNames) throws SQLException {
TableColumnInfo[] tciArr = con.getSQLMetaData().getColumnInfo(ti);
int[] result = new int[tciArr.length];
for (int i = 0; i < tciArr.length; i++) {
boolean found = false;
for (int j = 0; j < colNames.length && !found; j++) {
String columnName = colNames[j];
if (tciArr[i].getColumnName().equalsIgnoreCase(columnName)) {
result[i] = tciArr[i].getDataType();
found = true;
}
}
}
return result;
}
public static boolean tableHasPrimaryKey(ISQLConnection con, ITableInfo ti) throws SQLException {
boolean result = false;
ResultSet rs = null;
try {
DatabaseMetaData md = con.getConnection().getMetaData();
String cat = ti.getCatalogName();
String schema = ti.getSchemaName();
String tableName = ti.getSimpleName();
rs = md.getPrimaryKeys(cat, schema, tableName);
if (rs.next()) {
result = true;
}
}
finally {
SQLUtilities.closeResultSet(rs);
}
return result;
}
|