Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: problem with ODBC data source
|
Posted: Jul 4, 2002 11:20 PM
|
|
I originally thought that since this information is available from the ODBC API, there must be a way to access it with JDBC. After looking around, I can't find it. Maybe there is some obscure way to get the info with a special query to some special secret system table name?
If you are going to go the platform specific route, why not use the ODBC API? As distasteful as it is, it is still better than relying on a particular registry entry to be an accurrate or enduring source of information. You can do this either by making a little "proglet" that you call to generate a properties file (or INI file, in the Windows parlance), or you can do it with JNI.
Here is a little sample of the ODBC code that you would use. I'll leave the exercise of adapting it to JNI or dumping to an INI/properties file to the gentlereader.
void ShowDataSources()
{
const int lenny = 255;
char text[1024*16] = "Data Sources:\n";
char serverName[lenny+1];
int serverNameLength = 0;
char description[lenny+1];
int descriptionLength = 0;
SQLHENV env;
SQLAllocEnv( &env );
SQLRETURN sqlRet = 0;
sqlRet = SQLDataSources( env,
SQL_FETCH_FIRST,
(SQLCHAR *)serverName,
lenny,
(SQLSMALLINT *)&serverNameLength,
(SQLCHAR *)description,
lenny,
(SQLSMALLINT *)&descriptionLength );
switch( sqlRet )
{
case SQL_SUCCESS:
strcat( text, "SQL_SUCCESS!\n" );
break;
case SQL_SUCCESS_WITH_INFO:
strcat( text, "SQL_SUCCESS_WITH_INFO!\n" );
break;
case SQL_NO_DATA:
strcat( text, "SQL_NO_DATA!\n" );
break;
case SQL_ERROR:
strcat( text, "SQL_ERROR!\n" );
break;
case SQL_INVALID_HANDLE:
strcat( text, "SQL_INVALID_HANDLE!\n" );
break;
default:
strcat( text, "Unknown return value!\n" );
break;
}
while( sqlRet == SQL_SUCCESS || sqlRet == SQL_SUCCESS_WITH_INFO )
{
strcat( text, "\nServer Name: " );
strcat( text, serverName );
strcat( text, "\nDescription: " );
strcat( text, description );
sqlRet = SQLDataSources( env,
SQL_FETCH_NEXT,
(SQLCHAR *)serverName,
lenny,
(SQLSMALLINT *)&serverNameLength,
(SQLCHAR *)description,
lenny,
(SQLSMALLINT *)&descriptionLength );
}
MessageBox( NULL, text, "ODBC Info", MB_OK );
}
|
|