2017-08-04 113 views
0

我想从下面这段代码插入值:不能使静态参考非静态方法getUnit_id()从类型官

public int create(Officer officer) { 
    String sql = "insert into officer values(" + officer.getOfficer_id() + ", " + officer.getCollege_id() + ", " + Officer.getUnit_id() + ", " + officer.getRole_id() + ")"; 
    return template.update(sql); 
} 
+0

@ayanth添加你得到的例外,项目配置 –

+0

不能让一个静态引用从类型官 – Jayanth

+0

非静态方法getUnit_id()未能转换类型的值“的java.lang .String'为所需的类型'int';嵌套异常是java.lang.NumberFormatException:对于输入字符串:“create” – Jayanth

回答

1

这应该是一个编译错误。 getUnit_id不是一个静态方法,所以你需要使用一个Officer实例来调用它。

public int create(Officer officer) { String sql = "insert into officer values(" + officer.getOfficer_id() + ", " + officer.getCollege_id() + ", " + officer.getUnit_id() + ", " + officer.getRole_id() + ")"; return template.update(sql); }