NutzCN Logo
问答 sql server sql执行异常
发布于 46天前 作者 Hamming 139 次浏览 复制 上一个帖子 下一个帖子
标签:

SQL 数据库执行正常 但是 nutz执行异常

SELECT COLUMN_NAME as column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'wx_user';
    public Sql getPrimaryKey(String tableName) {
        String sqlstr = "SELECT COLUMN_NAME as column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = @tableName";
        Sql sql = Sqls.create(sqlstr);
        sql.params().set("tableName", tableName);
        sql.setCallback(Sqls.callback.entities());
        return sql;
    }

返回

com.alibaba.druid.pool.DruidPooledResultSet@706f8e55

日志

[DEBUG] 22:12:00.902 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:391) - SELECT COLUMN_NAME as column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = ?
    |       1 |
    |---------|
    | wx_menu |
  For example:> "SELECT COLUMN_NAME as column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'wx_menu'"

4 回复

entities回调需要entry

有的

    /**
     * 查询主键
     * @param tableName
     * @return
     */
    private String getPrimaryKey(String tableName) {
        Sql sql = getDbQuery().getPrimaryKey(tableName);
        Entity<String> entity = dao.getEntity(String.class);
        sql.setEntity(entity);
        dao.execute(sql);
        List<String> list = sql.getList(String.class);
        if(Lang.isNotEmpty(list) && list.size() >0){
            return list.get(0);
        }
        return null;
    }

String可不是entry

感谢兽总回复 改成酱紫 解决了

    /**
     * 查询主键
     * @param tableName
     * @return
     */
    private String getPrimaryKey(String tableName) {
        try{
            Sql sql = getDbQuery().getPrimaryKey(tableName);
            Entity<Record> entity = dao.getEntity(Record.class);
            sql.setEntity(entity);
            dao.execute(sql);
            List<Record> list = sql.getList(Record.class);
            if(Lang.isNotEmpty(list) && list.size() >0){
                return list.get(0).getString("column_name");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
添加回复
请先登陆
回到顶部