hi

I have create a table with 11 fields with field1 is primary key and auto incremented.
In java i use prepared statement.The code is working well without auto increment that is i add this value from my program. when i change field1 auto incremented and use prepared statement for 10 fields only, I have error "No value specified for parameter 1".

Also if I use prepared statement for 11 fields then what will b the parameters??
If i specified value of column1 then how it will be incremented in the database.
Please help me to fix the problem.
I the code is like this.

statement = connection.prepareStatement("INSERT INTO table1 VALUES(?,?,?,?,?,?,?,?,?,?,?)");
				
statement.setString(2, val2);
statement.setString(3, val3);
statement.setString(4, val4);
statement.setString(5, val5);
statement.setString(6, val6);
statement.setString(7, val7);
statement.setString(8, val8);
statement.setString(9, val9);
statement.setString(10, val10);
statement.setString(11, val11);

You may want to pay attention to setString(1,val1) as it should not interfere with the Primary key.

when I set the strings I start with the data needed and I do not attempt to alter the primary key so there are
six columns in the db but five values "?"
hope that helps.

I am not sure of what you may be up against. I just know that the following example works and it
may help you find your error.

good luck.


create table:

<entry key="createLocationAvailable"> CREATE TABLE location_available(
    record_num SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1,INCREMENT BY 1),
    loc_desc VARCHAR(70),
    available_start_date DATE,
    available_end_date DATE,
    available_start_time TIME,
    available_end_time TIME
    )
    </entry>

insert xml

<entry key="insertLocationAvailable">INSERT INTO location_Available(
    loc_desc,
    available_start_date,
    available_end_date,
    available_start_time,
    available_end_time)
    VALUES (?, ?, ?, ?, ?)
    </entry>

You may want to pay attention to setString(1,val1) as it should not interfere with the Primary key.

public boolean primaryInsertLocationAvailable() throws FileNotFoundException {


        boolean bInsert = true;
        setTableName(tableName);
        try {
            close(conn, ps);
            conn = connect();
            locationAvailableUser = MasterRegisterForm.locationAvailableBean;
            
            ps = (PreparedStatement) conn.prepareStatement(
                    ModelUtils.getXMLResource("insertLocationAvailable"));



            ps.setString(1, locationAvailableUser.getLocationDesc());            
            ps.setDate(2, (java.sql.Date) locationAvailableUser.getAvailableStartDate());
            ps.setDate(3, (java.sql.Date) locationAvailableUser.getAvailableEndDate());
            ps.setTime(4, (java.sql.Time)locationAvailableUser.getAvailableStartTime());
            ps.setTime(5,  (java.sql.Time)locationAvailableUser.getAvailableEndTime());


            int rowCount = ps.executeUpdate();
            if (rowCount != 1) {
                bInsert = false;
                throw new RegisterException();
            } else {
                throw new SuccessfullRegistrationMessage();
            }

        } catch (InterruptedException ex) {
            Logger.getLogger(LocationAvailableSupplementalDAO.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RegisterException e) {
            String x = e.getMessage();
            System.out.println("error message is: " + x);
            ViewUtils vu = new ViewUtils();
            vu.addExceptionMessage(x);
        } catch (SuccessfullRegistrationMessage e) {
            String x = e.getMessage();
            System.out.println("Curtasy message is: " + x);
            ViewUtils vu = new ViewUtils();
            vu.addMessage(x);
        } finally {
            try {
                close(conn, ps);
            } catch (SQLException e) {
                ModelUtils.log(e);
            }
        }
        return bInsert;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.