java - Webservice 返回空字符串而不是指定的字符串
问题描述
您好,我在 Java 中创建了返回有关注册用户的信息的 Web 服务。这是我的代码:
public String addUser(User user) {
List<String> initialValues = new ArrayList<String>();
try {
PreparedStatement prePreparedStatement = connection.prepareStatement("select count(*) as total from users where name='" + user.getName() + "'");
ResultSet rs = prePreparedStatement.executeQuery();
if (rs.next())
if (rs.getInt("total") > 0) {
return "user already exists";
}
PreparedStatement ps = connection.prepareStatement("insert into users(name,pass,level,exp,gold,session_id,reg_date,email) values (?, ?, ?, ?, ?, ?, ?, ?)");
ps.setString(1, user.getName());
ps.setString(2, user.getPass());
ps.setInt(3, 1);
ps.setInt(4, 1);
ps.setInt(5, 100);
ps.setString(6, "offline");
ps.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
ps.setString(8, user.getEmail());
ps.executeUpdate();
initialValues.add(getUserIdByNameAndPass(user.getName(), user.getPass()));
initialValues.add("1");
initialValues.add("0");
initialValues.add("5");
initialValues.add("100");
usersBasicInfoDao.addUsersBasicInfo(initialValues);
} catch (SQLException e) {
e.printStackTrace();
return e.getMessage();
}
return "added successfully";
}
但是每次添加用户时,它似乎return e.getMessage();
都是用空字符串调用而不是return "added successfully";
为什么会发生?
解决方案
推荐阅读
- slack - 如何通过 API 向 Slack 中的手机号码发送短信?
- sql - FULL JOIN 仅支持可合并连接的连接条件
- r - 从 excel 到 R 的非线性优化
- python - 检查一个项目是否比另一个大至少 1
- curl - curl:(56)接收失败:连接已重置,如何重试?
- structured-text - 结构化文本中的 C 样式函数?
- c# - 虚拟助手模板中的 ReturningUserIntroCard
- react-native - 如何在 Detox 中启用 `debug` 运行 RN 测试?
- python - 如何使用自定义项目结构设置 FLASK_APP
- javascript - 如何从异步方法输出值