利用PHPRPC协议,客户端访问服务端,查询数据库信息,求,小弟刚学习的初学者
利用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个,服务端能输出这个两个,但是在客户端确出错了。跪求哥哥姐姐们帮我看看
//客户端:
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个,服务端能输出这个两个,但是在客户端确出错了。跪求哥哥姐姐们帮我看看
异常
PHPRPC
范型
接口
- 1hibernate更动字段not null属性不生效
- 2为啥有的方法里面throw new 自定义错误类("") 外的方法外面有throws 有的没有
- 3hibernate多对多HQL查询的不解 各位大牛来指点一下吧
- 4action里面对数据库一系列操作 如何保证原子性呢
- 5表单提交的时分保存和返回只要两个图片就好了吗 不要具体的方法
- 6大家伙儿hibernate 的项目里用一级缓存和二级缓存吗
- 7JS如何实现页面按空格键的时候自动替换成‘’
- 8PreparedStatement的批量插入式无序的?该如何处理
- 9You have an error in your SQL syntax 找了一晚上不知道错哪了
- 10jquery如何样按顺序获取SRC的属性和文本框的值
- 上一篇:这个有关问题解决了,给40分儿
- 下一篇:求webservice视频教程解决方案
文章评论
相关解决方案