2014-01-22 22 views
0

服務器端代碼從數據庫檢索值。但我無法爲客戶提供價值。請幫助我。Web服務從服務器檢索數據,但客戶端無法訪問它們

服務器端代碼:

public int result(int ss) throws Exception 
{ 
     Class.forName("com.mysql.jdbc.Driver"); 
     String host="jdbc:mysql://localhost/test"; 
     String username="root"; 
     String password=""; 
     Connection connect=DriverManager.getConnection(host,username,password); 
     System.out.println("Works"); 
     Statement s =connect.createStatement(); 
     s.execute("select * from customer"); 
     ResultSet rs=s.getResultSet(); 
     while(rs.next()) 
     { 
       ss=rs.getInt(1); 
       System.out.println("Retrieved element is = " + ss); 
     } 
     return ss; 
} 

客戶端代碼:

public class sam { 

    public static void main(String[] args) throws RemoteException { 

     Sample1Stub stub = new Sample1Stub(); 
     Result method = new Result(); 
     method.getSs(); 
      ResultResponse response = stub.result(method); 
     System.out.println(response.get_return()); 
    } 
} 

回答

0

布爾執行(SQL字符串)

執行給定的SQL stateme nt,這可能會返回多個結果。在某些(不常見)情況下,單個SQL語句可能會返回多個結果集和/或更新計數。通常情況下,你可以忽略它,除非你(1)執行一個你知道可能返回多個結果的存儲過程,或者(2)你動態地執行一個未知的SQL字符串。 execute方法執行一條SQL語句並指出第一個結果的形式。然後,您必須使用getResultSet或getUpdateCount方法檢索結果,並使用getMoreResults移至任何後續結果。

執行給定的SQL語句,該語句返回一個ResultSet對象。 注意:此方法不能在PreparedStatement或CallableStatement上調用。

結果集的executeQuery(字符串SQL)

執行給定的SQL語句,該返回單個ResultSet對象。 注意:此方法不能在PreparedStatement或CallableStatement上調用。

s.execute(「select * from customer」);

,而不是用它

s.executeQuery( 「SELECT * FROM客戶」);

+0

沒問題,我從服務器端使用控制檯檢索數據庫中的值.later我爲服務器端編碼創建了Web服務,並嘗試在我的編碼的客戶端使用Web服務客戶端訪問..但是我得到的異常是:線程「main」中的異常org.apache.axis2.AxisFault:unknown – user3222661

相關問題