我在哪里使用Jackcess放置.mdb数据库文件..?

时间:2015-05-06 19:11:12

标签: java android jackcess

这可能是一个荒谬的问题,但我无法在任何地方找到答案......

我有一个名为test.mdb的Microsoft Access数据库。我使用Jackcess库尝试使用官方文档here

中的以下代码打开它
Database db = DatabaseBuilder.open(new File("mydb.mdb"));

听起来很简单,但我在哪里放置我的" test.mdb"?!

尝试放入assets文件夹并使用  文件:///android_asset/test.mdb 但那并没有帮助。我仍然得到FileNotFoundException

1 个答案:

答案 0 :(得分:0)

您必须先检查数据库文件。

  1. 如果db存在 - >打开它,
  2. 其他 - >创建一个新的。
  3. 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);
    
                        }
    

    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.

    这将在项目文件夹中创建新的数据库。

相关问题