我正在尝试从访问 mdb 文件的 Select * 创建文本文件,我编写了下面的代码来实现相同的功能,但是当我尝试读取数据时,我收到此错误“线程“主”java.sql.SQLException 中的异常: [Microsoft][ODBC Driver Manager] 无效的描述符索引”
不确定这种方法是否真的有效,代码如下:
//=============Extract contents in Access and save it as Text File Format==========================================
//String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test\\TestEJFolder\\BWC_Ejournal.mdb";
String connectionString ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\\test\\TestEJFolder\\BWC_Ejournal.mdb;";
DriverManager.getConnection(connectionString, "", "");
Connection conn = DriverManager.getConnection(connectionString, "", "");
String sql = "SELECT * FROM Events";
Statement cmd = conn.createStatement();
cmd.execute(sql);
ResultSet reader = cmd.executeQuery(sql);
//String path = "\\" + time_stmp + "_" + file_name;
File sw = new File(text_dir,file_name);
File ssw = new File(s_path);
sw.createNewFile();
final String format = "{0,-22} {1,-4} {2,-4} {3,-4} {4,-20} {5,-22}";
BufferedWriter output = new BufferedWriter(new FileWriter(sw));
String line = null;
//reader.beforeFirst();
//boolean b = true;
int colCount = rs.getColumnCount();
while (reader.next())
{
//Errors here while trying to read
line = String.format(format, String.format("{0:dd-MM-yyyy HH:mm:ss}", reader.getObject(5)).trim(), reader.getObject(0).toString().trim(), reader.getObject(1).toString().trim(), reader.getObject(2).toString().trim(), reader.getObject(3).toString().trim(), reader.getObject(4).toString().trim());
}
output.write(line);
output.close();
conn.close();