JDBC DatabaseMetaData getIndexInfo() returning null values
- From: Adam_R <Adam_R@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 9 Dec 2005 01:19:02 -0800
Using the DatabaseMetaData class’s method getIndexInfo seems to be returning
some strange information for the first result set object. For example after
createing a database with one table and one index, then connecting to it,
getting the meta data and calling getIndexInfo() I get the following results
TABLE_CAT : TestDataBase
TABLE_SCHEM : dbo
TABLE_NAME : Test
NON_UNIQUE : false
INDEX_QUALIFIER : null
INDEX_NAME : null
TYPE : 0
ORDINAL_POSITION : 0
COLUMN_NAME : null
ASC_OR_DESC : null
CARDINALITY : 0
PAGES : 0
TABLE_CAT : TestDataBase
TABLE_SCHEM : dbo
TABLE_NAME : Test
NON_UNIQUE : 1
INDEX_QUALIFIER : Test
INDEX_NAME : IDX_Test
TYPE : 3
ORDINAL_POSITION : 1
COLUMN_NAME : ColumnA
ASC_OR_DESC : A
CARDINALITY : null
PAGES : null
as you can see from above, the output for the first result set object
contained some strange values (null for INDEX_NAME etc). Is there any reson
for this or am I simply doing something wrong.
below is the sql used to created the database and the java class used to
generate the output above.
SQL Statments
==========
CREATE DATABASE TestDataBase
CREATE TABLE Test(
ColumnA varchar(20) default 'This Is A Test',
ColumnB int
)
CREATE INDEX IDX_Test on Test(ColumnA)
Java Class
=======
import java.sql.*;
public class IndexInfoTest {
public IndexInfoTest() {
Connection objConn = null;
String strDBName ="jdbc:microsoft:sqlserver://localhost:"+
"1433;databaseName=TestDataBase";
String strUserName = "tcuser";
String strPassword = "tcuser";
String strDriverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
try
{
Class.forName(strDriverName);
//get Connection
objConn =
DriverManager.getConnection(strDBName,strUserName,strPassword);
//get Meta Data
DatabaseMetaData objDBMetaData = objConn.getMetaData();
//getIndexInfo from Meta Data
ResultSet objResSet =
objDBMetaData.getIndexInfo(null,null,"Test",false,true);
//get the ResultSetMetaData
ResultSetMetaData objRSMD = objResSet.getMetaData();
//get the total columns in ResultSetMetaData
int intTotalColumns = objRSMD.getColumnCount();
//loop through printing off the result set objects
while(objResSet.next())
{
for(int i =1; i < intTotalColumns; i++)
System.out.println(objRSMD.getColumnName(i)+" :
"+objResSet.getString(i));
System.out.println("");
}
}
catch(Exception e){
e.printStackTrace();
}finally{
try
{
if(objConn!=null) objConn.close();
}catch(Exception e){e.printStackTrace();}
}
}
//main method
public static void main(String args[]){
IndexInfoTest iit = new IndexInfoTest();
}
}
we are using the following system setup
Driver Name : com.microsoft.jdbc.sqlserver.SQLServerDriver, SP 3, Version
2.2.0040
Java Version : Sun Micro Systems JDK 1.5.0_05
Operating System : Microsoft Windows Server 2003
SQL Server Version : Microsoft SQL Server 2000 SP4
Any help with this would be grately appreciated,
Adam
.
- Follow-Ups:
- Re: JDBC DatabaseMetaData getIndexInfo() returning null values
- From: Sue Purkis
- Re: JDBC DatabaseMetaData getIndexInfo() returning null values
- Prev by Date: Re: Possible Type Conversion Defect
- Next by Date: JDBC Meta Data getImportedKeys returns restrict not no action
- Previous by thread: Re: Possible Type Conversion Defect
- Next by thread: Re: JDBC DatabaseMetaData getIndexInfo() returning null values
- Index(es):