Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
1.4k views
in Programming by
edited by
I am new to ucanaccess. I am developing a java swing application, I am using MS Access 2016 to store my DB.I am trying to insert values into my table. I am using sql's insert into query. Everything seems right, but then I am getting error saying parameter marker not allowed (I think its referring to "?" which I used to pass variables to my query).

Here is the is the DB code:

public static void updateDB(String NOBOOKS, java.util.Date DOI, java.util.Date DOR){

     try{   

            Connection on = DriverManager.getConnection("jdbc:ucanaccess://Database/UserDetails.accdb");

            Statement stmt = on.createStatement();

            String sql = "SELECT * FROM Member";

            System.out.println(Uid);

            ResultSet result = stmt.executeQuery(sql);

            System.out.println(DOR);

            while(result.next()){

                if(Uid.equals(result.getString("ID"))){  

                    String N = NOBOOKS;

                    Date I = new Date(DOI.getTime());

                    Date R = new Date(DOR.getTime());

                    String sqlUpdate = "INSERT INTO Member (Issues,DOI,DOR) VALUES (?,?,?)";

                    PreparedStatement values = on.prepareStatement(sqlUpdate);

                    System.out.println("The DOI is "+ DOI);

                    System.out.println("The I is "+ I);

                    System.out.println("The DOR is "+ DOR);

                    System.out.println("The R is "+R);

                    

                    values.setString(1, N);

                    values.setDate(2, I);

                    values.setDate(3, R);

                    stmt.executeUpdate(sqlUpdate);

                }

            }

        }catch(Exception se){

            System.out.print(se);

        }   

    }

and this is the output i am getting.

2

Tue Sep 20 00:00:00 IST 2016

The DOI is Mon Sep 05 00:00:00 IST 2016

The I is 2016-09-05

The DOR is Tue Sep 20 00:00:00 IST 2016

The R is 2016-09-20

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 parameter marker not allowedBUILD SUCCESSFUL (total time: 25 seconds)

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)

Hi Sagar,

You need to use "executeUpdate()" without parameters. 

And line : "stmt.executeUpdate(sqlUpdate);" is senseless. 

You must use "values.executeUpdate()" instead of the line : "stmt.executeUpdate(sqlUpdate);".

Hope it helps.

by The go-to Tester (143 points)
Very accurate!
Thanks a lot @Mayur.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...