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();
}
{
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();
}
解决方案 »
- 一个javaScript问题
- ajaxtags框架报错-----java.lang.noclassdefounderror
- jms应用出错
- 下载J2EE视频教程朋友的快来啊
- struts初学疑问
- 急!编写数据库访问JAVABEAN组件,代码出错,特此求救~~~~~~~~~
- 请 CoolAbu(阿卜-Never Stop(★★★★)) 来领分! 多谢指点~
- 求助基于jdbc的clob的问题
- 立即给分100:环境jb8+sql server 2000+weblogic。在jb8中调试EJB(其实现和数据库的连接)客户端程序时,总报下边的错误。why???
- Hibernate 获取数据问题.
- 关于ant junit 报classnotfoundexception的问题
- 用jpanel显示图片调节大小后 图像不显示
这句去掉
是不是这行报错
如果是的话估计这个类没构造方法