【问题标题】:Web service retrieves Data from Server but Client can't access themWeb 服务从服务器检索数据,但客户端无法访问它们
【发布时间】:2014-01-22 09:22:07
【问题描述】:

服务器端代码从数据库中检索一个值。但我无法向客户端提供价值。请帮帮我。

服务器端代码:

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());
    }
}

【问题讨论】:

    标签: java eclipse web-services axis2


    【解决方案1】:

    布尔执行(字符串 sql)

    执行给定的 SQL 语句,该语句可能返回多个结果。在某些(不常见的)情况下,单个 SQL 语句可能会返回多个结果集和/或更新计数。通常你可以忽略这一点,除非你 (1) 执行一个你知道可能返回多个结果的存储过程,或者 (2) 你正在动态执行一个未知的 SQL 字符串。 execute 方法执行一条 SQL 语句并指示第一个结果的形式。然后,您必须使用方法 getResultSet 或 getUpdateCount 检索结果,并使用 getMoreResults 移动到任何后续结果。

    执行给定的 SQL 语句,该语句返回单个 ResultSet 对象。 注意:不能在 PreparedStatement 或 CallableStatement 上调用此方法。

    ResultSet executeQuery(String sql)

    执行给定的 SQL 语句,该语句返回单个 ResultSet 对象。 注意:不能在 PreparedStatement 或 CallableStatement 上调用此方法。

    s.execute("select * from customer");

    而不是它使用

    s.executeQuery("select * from customer");

    【讨论】:

    • 没有问题,我使用控制台从服务器端的数据库中检索了值。后来我为服务器端编码创建了 Web 服务,并尝试在客户端使用 Web 服务客户端进行访问我的编码..但我得到的异常是:线程“主”org.apache.axis2.AxisFault中的异常:未知
    猜你喜欢
    • 2012-12-07
    • 2014-03-26
    • 2017-05-19
    • 1970-01-01
    • 2012-04-08
    • 2013-12-27
    • 2021-01-25
    • 1970-01-01
    • 2010-10-27
    相关资源
    最近更新 更多