我正在学习网络服务。 我做了一个例子,我使用了Eclipse,MySql,Apache TomCat 8和Axis2。 这个项目包含一个简单的WebService,它连接到一个名为" users"制作CRUD流程。 问题是当我使用userDAO类创建webservice时,因为这些方法没有出现在列表Services中。 出现:
UserDAO
Service Description : Please Type your service description here
Service EPR : http://localhost:8080/ExemploWS/services/UsuarioDAO
Service Status : Active
There are no Operations specified
发生了什么?
UserClass的:
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.PreparedStatement;
public class UserDAO {
public boolean insertUser(User user){
try {
Connection conn = ConectaMySql.obtemConexao();
String queryInsert = "INSERT INTO USER VALUES (null,?,?)";
PreparedStatement ppStm = conn.prepareStatement(queryInsert);
ppStm.setString(1, user.getName());
ppStm.setInt(2, user.getAge());
ppStm.executeUpdate();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
public boolean updateUser(User user){
try {
Connection conn = ConectaMySql.obtemConexao();
String queryInsert = "UPDATE USUARIO SET name = ?, age = ?, WHERE id = ?)";
PreparedStatement ppStm = conn.prepareStatement(queryInsert);
ppStm.setString(1, user.getName());
ppStm.setInt(2, user.getAge());
ppStm.setInt(3, user.getId());
ppStm.executeUpdate();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
public boolean deleteUser(User user){
try {
Connection conn = ConectaMySql.obtemConexao();
String queryInsert = "DELETE FROM USUARIO WHERE id=?";
PreparedStatement ppStm = conn.prepareStatement(queryInsert);
ppStm.setInt(1, user.getId());
ppStm.executeUpdate();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
public ArrayList<User> searchAllUsers(){
ArrayList<User> list = new ArrayList<User>();
try {
Connection conn = ConectaMySql.obtemConexao();
String queryInsert = "SELECT * FROM user";
PreparedStatement ppStm = conn.prepareStatement(queryInsert);
ResultSet rSet = ppStm.executeQuery();
while(rSet.next()){
User usr = new User();
usr.setId(rSet.getInt(1));
usr.setName(rSet.getString(2));
usr.setAge(rSet.getInt(3));
list.add(usr);
}
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public User searchUserById(int id) {
User usr = null;
try {
Connection conn = ConectaMySql.obtemConexao();
String queryInsert = "SELECT * FROM user WHERE id=?";
PreparedStatement ppStm = conn.prepareStatement(queryInsert);
ppStm.setInt(1, id);
ResultSet rSet = ppStm.executeQuery();
if(rSet.next()){
usr = new User();
usr.setId(rSet.getInt(1));
usr.setName(rSet.getString(2));
usr.setAge(rSet.getInt(3));
}else{
return usr;
}
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return usr;
}
public boolean deleteUser(int id){
return deleteUser(new User(id,"",0));
}
}
答案 0 :(得分:0)
所以,我有时候为了解决这个问题而重启日食。