0

i need to create a table in access database and for that i used the following code. It is creating table but it throws error like "Reserved Error (-5001) and there is no reason for this error" when the table is clicked.

My code:

public class NewClass {
public static void main (String args[])
{
    String dbFileSpec = "C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\AutomateExcelDatabase\\Centre.accdb";
    try (Connection conn = DriverManager.getConnection(
            "jdbc:ucanaccess://" + dbFileSpec
            + ";newdatabaseversion=V2007")) {
        DatabaseMetaData dmd = conn.getMetaData();
        try (ResultSet rs = dmd.getTables(null, null, "Clients", new String[]{"TABLE"})) {
            if (rs.next()) {
                System.out.println("Table [Clients] already exists.");
            } else {
                System.out.println("Table [Clients] does not exist.");
                try (Statement s = conn.createStatement()) {
                    s.executeUpdate("CREATE TABLE Clients (ID COUNTER PRIMARY KEY, LastName TEXT(100))");
                    System.out.println("Table [Clients] created.");
                }
            }
        }
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}

Suggest some idea to resolve this error.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Dhinakar
  • 4,061
  • 6
  • 36
  • 68

3 Answers3

2

Your issue might be resolved by using the latest version of UCanAccess. You can download it from here:

http://sourceforge.net/projects/ucanaccess/files/latest/download

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Prasath Bala
  • 698
  • 1
  • 7
  • 12
0

Please refer this link. It will give you an idea

http://www.personalcomputerfixes.com/general-fixes/5001-error-fix-%E2%80%93-how-to-resolve-the-5001-error-on-windows/

Prasath Bala
  • 698
  • 1
  • 7
  • 12
  • 1
    From [How do I write a good answer?](http://stackoverflow.com/help/how-to-answer): *"Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline."* - Please take a moment to [edit] your answer to include the relevant information (hint: there isn't any) or consider deleting this answer. – Gord Thompson Oct 30 '14 at 10:04
0

I noticed that the reason of the -5001 error is the data type COUNTER used in the example, I replaced it with data type NUMBER and everything went well.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Riad
  • 1