Menu

Getting an error while inserting in database

Help
Vishal
2015-03-11
2015-03-16
  • Vishal

    Vishal - 2015-03-11

    I am getting an error "nullnet.ucanaccess.jdbc.UcanaccessSQLException: invalid cursor state: all column must be set before insert"

    here is my code

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    Connect("net.ucanaccess.jdbc.UcanaccessDriver","jdbc:ucanaccess://D:/chatBase.mdb","","");

         System.out.println("connected to db1 ");
         if(session.getAttribute("userName")!=null){
    
             System.err.print(tempName);
             userName=session.getAttribute("userName").toString();
             try{
                 rs=st.executeQuery("select count(userid) from users where nickname='"+userName+"'");
                 int count =0;
                 while(rs.next()){
                     count=rs.getInt(1);
                 }
    
                 if(count==0){
                 rs=st.executeQuery("select * from users");
    
                 rs.moveToInsertRow();
    
                 rs.updateString("NickName",userName);
    
                 rs.insertRow();
    
                 }
             }catch(Exception ex){
                 ex.printStackTrace();
             }
    
         }
    
     
  • Gord Thompson

    Gord Thompson - 2015-03-11

    UCanAccess uses HSQLDB as a "backing database", and HSQLDB requires that all columns in the insert row be given an explicit value before calling .insertRow(), including using rs.updateNull("ColumnName") to explicitly specify a NULL value. That's just the way it works.

    This was previously discussed on this forum in this thread.

     
  • Marco Amadei

    Marco Amadei - 2015-03-16

    Yes, I confirm what Gord states.
    But some complaints has been raised about this current behaviour and I can do something before redirecting to HSQLDB.
    They say the implentation of this feature in other drivers for other dbms is simpler for use. So, in the next release, I'll change this behaviour so that you're no more forced to explicitly set the values of all columns (i.e., the null values).
    Cheers Marco

     

    Last edit: Marco Amadei 2015-03-16

Log in to post a comment.