title: Export Access Database to text File Java
body: <p>I am trying to create text file from Select * of access mdb file, I wrote below code to implement same, but while I am trying to read the data I am getting this error "Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid descriptor index"</p>
  
  <p>Not sure if this method will actually work, here's the code:</p>
  
  <pre><code>//=============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();
  </code></pre>