JDBC Column Name Not Writing

I am using the following to return a results set from SQL Server and writing it to a text file. The data in the writes to the file, but I can not get the column name to write to the file.

flNewExcelFile oflTemp = new flNewExcelFile();

File flTemp = oflTemp.svFile();

BufferedWriter outData = new BufferedWriter(new FileWriter(flTemp));

String dtRow;

ResultSet rsRs = rsSPResult.rsObj();

ResultSetMetaData mtdData = rsRs.getMetaData();

int cols = mtdData.getColumnCount();

for (int i=1;i<=cols;i++)

{

dtRow = mtdData.getColumnName(i);

outData.write(dtRow);

outData.newLine();

}

while (rsRs.next())

{

for (int i=1;i<=cols;i++)

{

dtRow = rsRs.getString(mtdData.getColumnName(i));

outData.write(dtRow);

outData.newLine();

}

}

outData.close();

I am connecting to the data via a DSN-Less connection:

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String sourceURL = "jdbc:odbc:DRIVER={SQL Server}; Server=ServerName;Database=dataBaseName";

databaseConnection = DriverManager.getConnection(sourceURL,"UserID","PW");

}

And creating the results set:

Statement sqlStatement = conn.createStatement();

ResultSet rsData = sqlStatement.executeQuery("Select * From Contract");

TIA

[1445 byte] By [btpull] at [2007-9-26 1:53:06]
# 1

> but I can not get the column name to write to the file.

what happens?

looks like you are writing an m$ excel sheet.

1. you are possibly missing something in the steps needed to get column names into you flNewExcelFile object.

2. are you getting the columns names as a row, rather than the header?

if that is so, you might have to write the column names in some particular manner.

3. what is this flNewExcelFile class. the documentation to flNewExcelFile might give you the answer, if it is a third party class.

parthasarkar at 2007-6-29 3:03:44 > top of Java-index,Archived Forums,Java Programming...
# 2
try using getColumnLabel() function of ResultSetMetaData mtdData.getColumnLabel(i).bye
sundaram123 at 2007-6-29 3:03:44 > top of Java-index,Archived Forums,Java Programming...
# 3
Did you first try printing all the stuff on the console? I think there could be a problem with that BufferedWriter
kantle at 2007-6-29 3:03:44 > top of Java-index,Archived Forums,Java Programming...
# 4
If there is a problem with BufferedWriter? Try printing the stuff on stdout first (with System.out.println)
kantle at 2007-6-29 3:03:44 > top of Java-index,Archived Forums,Java Programming...
# 5
If there is a problem with BufferedWriter? Try printing the stuff on stdout first (with System.out.println)
kantle at 2007-6-29 3:03:44 > top of Java-index,Archived Forums,Java Programming...