JSONObject cannot be resolved to a type

yanjing0923 2011-08-03 12:34:21
public String addUser(String json)
{
JSONObject jsonObj = JSONObject.fromObject(json);
JSONObject outJson = new JSONObject();
Users user = (Users) JSONObject.toBean(jsonObj, Users.class);
try {
connection = dataSource.getConnection();
if (connection != null) {
connection.setAutoCommit(false);
String sql = "insert into users (id, name, email, qq,phone) values (?,?,?,?,?)";
pst = connection.prepareStatement(sql);
pst.setString(1, YyID.getUUID32());
pst.setString(2, user.getName());
pst.setString(3, user.getEmail());
pst.setString(4, user.getQq());
pst.setString(5, user.getPhone());
int count = pst.executeUpdate();
connection.commit();
connection.setAutoCommit(true);
if (count == 1) {
outJson.put("retCode", "0100");
outJson.put("retMsg", "add employee successfully.");
} else {
outJson.put("retCode", "0001");
outJson.put("retMsg", "add employee failed.");
}
}
} catch (SQLException e) {
try {
if (connection != null)
connection.rollback();
connection.setAutoCommit(true);
} catch (SQLException e1) {
e1.printStackTrace();
}
outJson.put("retCode", "0003");
outJson.put("retMsg", "mysql execute error.");
e.printStackTrace();
} finally {
try {
if (pst != null)
pst.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return outJson.toString();
}
...全文
3111 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zl3450341 2011-08-03
  • 打赏
  • 举报
回复
不能识别JSONObject

是不是你的jar包没导入列?
yanjing0923 2011-08-03
  • 打赏
  • 举报
回复
刚接触JAVA,JSON这个实在是不明白,希望高手指点一下
大灰兔 2011-08-03
  • 打赏
  • 举报
回复
你这个错误是由于导入了重复的jar包导致的,你检查下是否导入了两个不同的版本或者在两个路径下面都导入了json的jar包.像上面几位说的没导入jar包会报NoClassDeffoundError错误的.
敬敬11 2011-08-03
  • 打赏
  • 举报
回复
你可以先删除,再引入一遍,这个是jar包的问题
小绵羊 2011-08-03
  • 打赏
  • 举报
回复
有把JSONObject import进来么
剑神一笑 2011-08-03
  • 打赏
  • 举报
回复
JSONObject outJson = new JSONObject();
这句去掉
是不是这行报错
如果是的话估计这个类没构造方法
yanjing0923 2011-08-03
  • 打赏
  • 举报
回复
库中存在这个包,而且已经导入了,就是一直提示这个错误····不知道为啥???

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧