利用PHPRPC协议,客户端访问服务端,查询数据库信息,求高手指点,小弟刚学习的菜鸟
//客户端:
public class Client {
/**
* @param args
* @throws
SQLException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PHPRPC_Client client = new PHPRPC_Client("http://localhost:8080/GovernmentAffairs/Query");
INewsService inews = (INewsService) client.useService(INewsService.class);//创建服务端类
ArrayList<String> news_tit = new ArrayList<String>();
news_tit = inews.GetAllNews();
System.out.println(news_tit.isEmpty());
System.out.println(news_tit.size());
for (int i = 0; i < news_tit.size(); i++) {
System.out.println(news_tit.get(i));
}
}
}
//服务端:
public class NewsQuery extends DataConnection implements INewsService {
private Connection conn;
public ArrayList<String> GetAllNews() {
ArrayList<String> list = new ArrayList<String>();
String sql = "SELECT * FROM government_business_news";
try {
this.conn = DataConnection.getConn();
this.stm = conn.createStatement();
this.rst = this.stm.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
try {
while (this.rst.next()) {
Business_news news = new Business_news();
news.setNews_title(rst.getString("news_title"));
list.add(news.getNews_title());
}
;
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(list.size());
System.out.println(list.isEmpty());
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
return list;
}
}
我在服务端能够用for循环输出list中的数据,但是在客户端报错了(最后一行输出):Exception in thread "main"
java.lang.ClassCastException: [B cannot be cast to java.lang.String
at com.aoda.zm.bussiness.Client.main(Client.java:31)
客户端我测试了news_tit这个list中size有2个,服务端能输出这个两个,但是在客户端确出错了。跪求哥哥姐姐们帮我看看