Mumfi
Mumfi

Reputation: 425

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

Upvotes: 1

Views: 414

Answers (1)

Yavuz Oğuz Kaymakcı
Yavuz Oğuz Kaymakcı

Reputation: 11

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.

Upvotes: 1

Related Questions