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

