简体   繁体   中英

Where do i put the .mdb database file using Jackcess..?

This might be a ridiculous question, but I can't find an answer anywhere...

I have a Microsoft Access database called test.mdb. I use the Jackcess library to try to open it using the following code taken from official documentation here

Database db = DatabaseBuilder.open(new File("mydb.mdb"));

Sounds simple enough, but where exactly do I place my "test.mdb"?!

Tried putting in the the assets folder and used file:///android_asset/test.mdb but that didn't help. I still get FileNotFoundException

You must check database file first.

  1. if db exists -> open it,
  2. else -> create a new one.

1.

 File dbfile = new File("mydb.mdb");
            public void Connect() {
                try {

                if (dbfile.exists() && !dbfile.isDirectory()) {

                    db = DatabaseBuilder.open(dbfile);


                } else {

                    int warning= JOptionPane.showConfirmDialog(null, "Yeni bir veritabanı oluşturulsunmu?", "Mevcut Bir Veritabanı Bulunamadı",
                            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

                    if (uyari == JOptionPane.YES_OPTION) {
                        Create();
                    } else {

                        System.exit(0);

                    }

2.

  public void Olustur() { try { db = DatabaseBuilder.create(Database.FileFormat.V2010, dbfile); } catch (IOException ex) { } 

This will create new db on your project folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM