Menu

MS Access unable to delete using date as criteia

Help
Lon Parisi
2020-06-16
2020-07-26
  • Lon Parisi

    Lon Parisi - 2020-06-16

    Hello,

    I've been experiencing a strange problem. When I execute the following command:
    delete from dislocations where market_date < #2020-06-15# in MS Access SQL it works fine. When I do the exact same thing/command in Java, I get a very unexpected error. Here is my java code:
    private void clearOldDislocations() {
    try {
    String sql = "delete from dislocations where market_date < #" + msafmt.format(this.endDate) + "#";
    System.out.println(sql);
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.executeUpdate();
    conn.commit();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

        Here is the error I get:
        delete from dislocations where market_date < #2020-06-15#
    

    java.lang.NumberFormatException
    at java.math.BigDecimal.<init>(Unknown Source)
    at java.math.BigDecimal.<init>(Unknown Source)
    at java.math.BigDecimal.<init>(Unknown Source)
    at net.ucanaccess.commands.IndexSelector$ColumnMatcher.matches(IndexSelector.java:75)
    at net.ucanaccess.commands.AbstractCursorCommand.currentRowMatches(AbstractCursorCommand.java:32)
    at net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:86)
    at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:323)
    at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205)
    at com.baml.voldislocation.DislocationScreener.clearOldDislocations(DislocationScreener.java:80)
    at com.baml.voldislocation.DislocationScreener.runData(DislocationScreener.java:63)
    at com.baml.voldislocation.DislocationScreener.main(DislocationScreener.java:36)
    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 null
    at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:212)
    at com.baml.voldislocation.DislocationScreener.clearOldDislocations(DislocationScreener.java:80)
    at com.baml.voldislocation.DislocationScreener.runData(DislocationScreener.java:63)
    at com.baml.voldislocation.DislocationScreener.main(DislocationScreener.java:36)</init></init></init>

        I have no idea why there is an issue.  There are no blanks.  In addition, I copied the table's structure and renamed the old one to see if there was the possibility the table was corrupt in some way.
    
     
  • Gord Thompson

    Gord Thompson - 2020-07-26

    I can reproduce the issue with the attached .accdb file.

    screenshot

    PS C:\Users\Public\Downloads\UCanAccess> ./console.bat
    java version "1.8.0_241"
    Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
    Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
    
    Please, enter the full path to the access file (.mdb or .accdb): C:\Users\Gord\Desktop\infinity.accdb
    Loaded Tables:
    
    Loaded Queries:
    
    Loaded Procedures:
    
    Loaded Indexes:
    Primary Key  on Table1 Columns: (ID)
    
    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::5.0.0-SNAPSHOT null
            at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:231)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at net.ucanaccess.console.Main.main(Main.java:151)
    Caused by: java.lang.NumberFormatException
            at java.math.BigDecimal.<init>(Unknown Source)
            at java.math.BigDecimal.<init>(Unknown Source)
            at java.math.BigDecimal.<init>(Unknown Source)
            at net.ucanaccess.converters.LoadJet$TablesLoader.value(LoadJet.java:1126)
            at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableData(LoadJet.java:859)
            at net.ucanaccess.converters.LoadJet$TablesLoader.loadTableData(LoadJet.java:837)
            at net.ucanaccess.converters.LoadJet$TablesLoader.loadTablesData(LoadJet.java:1029)
            at net.ucanaccess.converters.LoadJet$TablesLoader.loadTables(LoadJet.java:1077)
            at net.ucanaccess.converters.LoadJet$TablesLoader.access$3200(LoadJet.java:264)
            at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1579)
            at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:218)
            ... 3 more
    UCAExc:::5.0.0-SNAPSHOT null
    Press any key to continue . . .
    
     

    Last edit: Gord Thompson 2020-07-26

Log in to post a comment.