I've been trying to get the datatype names from SQL Server 7, but it
keeps on giving me null as the TYPE_NAME, does anyone know a way to
get the dbms datatype names? It used to work with SQL Server 6.5.
Using: JDK1.1.5, JDBC-ODBC bridge, ODBC version 3.70.06.23, SQL Server
7.
I've tried this with DatabaseMetaData.getColumns() and
DatabaseMetaData.getTypeInfo() to no avail.
Here's a function which should list data types:
/**
* read supported database types from metadata
*/
public void readDataTypes() throws CException
{
if (myConnection == null)
{
throw new CException("Could not get database info: not connected",
ERR_CONNECT);
}
DatabaseMetaData metaDB = null;
try
{
metaDB = myConnection.getMetaData();
}
catch (Exception e)
{
CException e2 = new CException("Could not get database meta data,
aborting connection", ERR_META);
disconnect();
throw e2;
}
try
{
ResultSet rs = metaDB.getTypeInfo();
ResultSetMetaData rsd = rs.getMetaData();
int end = rsd.getColumnCount();
while (rs.next())
{
System.out.println("New Type");
for (int count = 1 ; count <= end ; count++)
{
String name = rsd.getColumnName(count);
Object data = rs.getObject(count);
System.out.println("\t" + name + ' ' + data);
}
}
}
catch (Exception e3)
{
throw new CException("Error reading database data types " +
e3.getMessage());
}
}
--------------------------------------------
This is the output I get:
New Type
TYPE_NAME null
DATA_TYPE -11
COLUMN_SIZE 36
LITERAL_PREFIX '
LITERAL_SUFFIX '
CREATE_PARAMS null
NULLABLE 1
CASE_SENSITIVE 0
SEARCHABLE 2
UNSIGNED_ATTRIBUTE null
FIXED_PREC_SCALE 0
AUTO_UNIQUE_VALUE null
LOCAL_TYPE_NAME null
MINIMUM_SCALE null
MAXIMUM_SCALE null
SQL_DATA_TYPE -11
SQL_DATETIME_SUB null
NUM_PREC_RADIX null
INTERVAL_PRECISION null
USERTYPE 0
New Type
TYPE_NAME null
DATA_TYPE -10
COLUMN_SIZE 1073741823
LITERAL_PREFIX N'
LITERAL_SUFFIX '
CREATE_PARAMS null
NULLABLE 1
CASE_SENSITIVE 0
SEARCHABLE 1
UNSIGNED_ATTRIBUTE null
FIXED_PREC_SCALE 0
AUTO_UNIQUE_VALUE null
LOCAL_TYPE_NAME null
MINIMUM_SCALE null
MAXIMUM_SCALE null
SQL_DATA_TYPE -10
SQL_DATETIME_SUB null
NUM_PREC_RADIX null
INTERVAL_PRECISION null
USERTYPE 0
..... and so on
--
http://wkweb4.cableinet.co.uk/jacquesL