2014-11-04 43 views
0

我在研究Web服務。 我做了一個例子,我使用Eclipse,MySql,Apache TomCat 8和Axis2。 該項目由一個簡單的WebService組成,該WebService連接到一個名爲「users」的表來進行CRUD過程。 問題是,當我使用userDAO類創建webservice時,因爲這些方法未出現在列表Services中。 出現:在WSDL中沒有指定操作

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

所以,我不得不有時重啓蝕爲解決這個問題。