import com.jacob.com.*;
import com.jacob.activeX.*;
public class Lesson003
{
public static void main(String[] args) {
ActiveXComponent cn = new ActiveXComponent("DAO.DBEngine.36");
try {
Dispatch db = Dispatch.call(cn ,"OpenDatabase", "C:\\********.mdb", false, true).toDispatch();
StringBuffer sb = new StringBuffer();
sb.append("select *\n");
sb.append("from [********]\n");
Dispatch rs = Dispatch.call(db, "OpenRecordset", sb.toString(), 8).toDispatch();
boolean eof = Dispatch.get(rs, "EOF").getBoolean();
while (!eof) {
Dispatch fields = Dispatch.get(rs, "Fields").toDispatch();
int count = Dispatch.get(fields, "Count").getInt();
for (int i=0;i<count;i++) {
Dispatch fd = Dispatch.call(fields, "Item", i).toDispatch();
Variant v = Dispatch.call(fd, "Value");
if (!v.isNull())
System.out.print(v.toString());
System.out.print('\t');
}
System.out.println();
Dispatch.call(rs, "MoveNext");
eof = Dispatch.get(rs, "EOF").getBoolean();
}
Dispatch.call(rs ,"Close");
Dispatch.call(db ,"Close");
} catch (Exception e) {
e.printStackTrace();
} finally {
ComThread.Release();
}
}
}