3 Replies Latest reply: Jun 10, 2005 10:35 AM by jschellSomeoneStoleMyAlias RSS

    problem loading Access DB?

    807597
      hello friends

      i am working on a project using ms access as database.
      i am using dsn-less connection for my project. here, i can
      use only xxx.mdb or complete path like (c:/Inventory/src/project/inventory.mdb)
      of the xxx.mdb. but i want to use only xx.mdb instead of complete path.

      i am using netBeans IDE which creates a list directories &
      the mdb file is stored where all the .java & .class files are stored.

      please help me

      regards
      anandaScreen
        • 1. Re: problem loading Access DB?
          807597
          Hi
          try this code
          --
          try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          // set this to a MS Access DB you have on your machine
          String filename = "Authors.mdb";
          String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
          database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
          // now we can get the connection from the DriverManager
          Connection con = DriverManager.getConnection( database ,"",""); 
          stat=con.createStatement();
          rs=stat.executeQuery("Select * from `Authors`");
          while (rs.next())
          {
          System.out.println(rs.getString(1)+" "+rs.getString(2));
          }
          rs.close();
          }
          catch(Exception E)
          {
          
          }
          Authors.mdb is in same folder of class and works fine.
          • 2. Re: problem loading Access DB?
            jschellSomeoneStoleMyAlias
            i am working on a project using ms access as
            database.
            i am using dsn-less connection for my project. here, i can
            use only xxx.mdb or complete path like
            (c:/Inventory/src/project/inventory.mdb)
            of the xxx.mdb. but i want to use only xx.mdb
            b instead of complete path.
            The ODBC driver for Access (nothing to do with java) is file based.

            So you are restricted in the same way that you are restricted when using files.

            As suggested by the previous post if the database file is in the execution directory then you you can use it without the directory part. That is the only way.
            • 3. Re: problem loading Access DB?
              807600
              Can you please tell me what is the DeriverID in the syntax?