Error in executeUpdate, Invalid character string format for type long.

41 views
Skip to first unread message

ksco...@gmail.com

unread,
Jan 29, 2017, 12:42:31 AM1/29/17
to sql2o
I am trying out this library so this most likely a silly mistake on my part.

Here is my in memory Apache Derby table :

              String sql="CREATE TABLE Author ("
                      + "author_id BIGINT  NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),"
                      + "first_name VARCHAR(40),"
                      + "last_name VARCHAR(40) "
                      //+ "PRIMARY_KEY(author_id)"
                      + ")";

Here is the code I am using.   It does a simple update with a where clause: 

public void update(Author entity)  {
 
       
        String sql="UPDATE author SET first_name=:firstName ,last_name=:lastName WHERE author_id = :authorId";
    
        Long id=entity.getAuthorId();
        log.debug("id="+id );
        try (Connection con = sql2o.open()) {
            int rows=con.createQuery(sql)
                .addParameter("authorId", id )
                .addParameter("firstName", entity.getFirstName() )
                .addParameter("lastName", entity.getLastName() )
                .executeUpdate()
                .getResult();
            log.debug("rows="+rows);
        }
       
    } 

Николай Митропольский

unread,
Feb 1, 2017, 7:20:12 AM2/1/17
to sql2o, ksco...@gmail.com
Hello!

Probably you should provide additional info, for example about versions of libraries you use. Because in my case your code successfully works.

BR, Nicolay

воскресенье, 29 января 2017 г., 8:42:31 UTC+3 пользователь ksco...@gmail.com написал:

ksco...@gmail.com

unread,
Feb 5, 2017, 1:46:31 PM2/5/17
to sql2o, ksco...@gmail.com
I re-tested with the latest Apache  Derby v10.13.1.1 and I now have no issues.  So I guess I just picked a bad version from  MVN central.

Thanks,
Reply all
Reply to author
Forward
0 new messages