+ Reply to Thread
Results 1 to 3 of 3

Thread: Cannot use DBLoginMySQL template to insert record but use console to insert which ok

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot use DBLoginMySQL template to insert record but use console to insert which ok

    I found the insert error when execute the following method which copied from the DBLoginMySQL template. Please advise.

    #ERROR
    com.electrotank.electroserver5.examples.dblogin.Co ntroller - start addnewusername
    2012-Jul-20 13:38:24:492 [New I/O server worker #1-1] ERROR com.electrotank.electroserver5.examples.dblogin.Co ntroller - Controller.registerNewUser error:
    2012-Jul-20 13:38:24:495 [New I/O server worker #1-1] DEBUG Extensions.DBLoginMySQL.Plugins.DatabasePlugin - result name = DatabaseError


    #Controller.java
    public LoginResultEnum registerNewUser(final String username, final String zoneid, final String roomid, final String logintime, final String createby, final String logouttime, final String updateby, final String remark) {
    UserObject userinroomlist = new UserObject();
    userinroomlist.setUsername(username);
    userinroomlist.setZoneid(zoneid);
    userinroomlist.setRoomid(roomid);
    userinroomlist.setLogintime(logintime);
    userinroomlist.setCreateby(createby);
    userinroomlist.setLogouttime(logouttime);
    userinroomlist.setUpdateby(updateby);
    userinroomlist.setRemark(remark);
    synchronized (this) {
    UserObject otherUser = getUserInfo(username);
    //if (otherUser == null) {
    // register
    try {
    getDbi().inTransaction(new TransactionCallback<Object>() {

    @Override
    public Object inTransaction(Handle handle, TransactionStatus status) throws Exception {
    addNewUsername(handle, username, zoneid,roomid,logintime,createby,logouttime,update by,remark);
    return null;
    }
    });
    } catch (Throwable t) {
    logger.error("Controller.registerNewUser error: ", t.getMessage());
    t.printStackTrace();
    return LoginResultEnum.DatabaseError;
    }

    return LoginResultEnum.Approved;
    //} //else if (otherUser.doesPasswordMatch(password)) {
    //return LoginResultEnum.AlreadyRegistered;
    //}
    //else {
    // return LoginResultEnum.UsernameTaken;
    //}
    }
    }

    private void addNewUsername(Handle handle, String userName, String zoneid, String roomid, String logintime, String createby, String logouttime, String updateby, String remark) {
    logger.debug(userName);
    logger.debug(zoneid);
    logger.debug(roomid);
    logger.debug(logintime);
    logger.debug(createby);
    logger.debug(logouttime);
    logger.debug(updateby);
    logger.debug(remark);
    logger.debug("start addnewusername");
    handle.createStatement("sql/AddNewUsername.sql")
    .bind("username", userName)
    .bind("zoneid", zoneid)
    .bind("roomid", roomid)
    .bind("logintime", logintime)
    .bind("createby", createby)
    .bind("logouttime", logouttime)
    .bind("updateby", updateby)
    .bind("remark", remark)
    .execute();
    logger.debug("addNewUsername completed");
    }

    But I can login to the mysql db server and use the same user to insert the table with successfully, why ?? What does the error mean ?

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    # AddNewUsername.sql as belows

    -- Adds a new username to the database
    insert into userinroomlist (username, zoneid, roomid, logintime, createby, logouttime, updateby, remark)
    values (:username, :zoneid, :roomid, :logintime, :createby, :logouttime, :updateby, :remark)

  3. #3
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,219
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    Is your extension able to read the database table? Test that first. If it can read but not write, this is quite strange. If it can't read, then you aren't connecting properly to the database.

    Another recent thread had problems connecting to MySQL locally that were resolved by setting the MySQL configuration to enable TCP/IP Networking. My own local MySQL enables both that and also strict mode.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts