private void huSelect() throws Exception {
// TODO Auto-generated method stub
System.out.println("输入要查询的户(门)编号:");
int hid = input.nextInt();
List list = sc.huselect(hid);
if(list.size() == 0) {
System.out.println("该户(门)不存在!");
return;
}
for (int i = 0; i < list.size(); i++) {
Hu h = (Hu)list.get(i);
System.out.println(h);
}
}
public List huselect(int hid) throws Exception {
// TODO Auto-generated method stub
Socket sck = new Socket("localhost", 10001);
DataOutputStream dout = new DataOutputStream(sck.getOutputStream());
dout.writeInt(5);
//发送参数到服务端
DataOutputStream dout2 = new DataOutputStream(sck.getOutputStream());
dout2.writeInt(hid);
//接收服务端传回的信息
ObjectInputStream oin = new ObjectInputStream(sck.getInputStream());
List list = (List) oin.readObject();
oin.close();
dout2.close();
dout.close();
sck.close();
return list;
}
private void huselect() throws Exception {
// TODO Auto-generated method stub
DataInputStream din = new DataInputStream(sck.getInputStream());
int hid = din.readInt();
List list = hdao.selectOne(hid);
//发送客户端
ObjectOutputStream out = new ObjectOutputStream(sck.getOutputStream());
out.writeObject(list);
out.close();
din.close();
}
public List selectOne(int hid) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shoulouchu", "root", "mysql");
String sql = "select * from hu where hid=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, hid);
List list = new ArrayList();
ResultSet rs = ps.executeQuery();
while(rs.next()) {
int lid = rs.getInt(1);
int hdanyuan = rs.getInt(2);
int hlouceng = rs.getInt(3);
int hstate = rs.getInt(5);
Hu h = new Hu(lid, hdanyuan, hlouceng, hid, hstate);
list.add(h);
}
con.close();
return list;
}
总是报错,求大神
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.heimao.model.Hu
操作有误!
1、户(门)查询;2、户(门)展示;3、户(门)新增;4、退出;
at com.heimao.ctrl.ShoulcCtrl.huselect(ShoulcCtrl.java:105)
at com.heimao.view.HuView.huSelect(HuView.java:130)
at com.heimao.view.HuView.menu(HuView.java:23)
at com.heimao.view.AdminView.menu(AdminView.java:31)
at com.heimao.view.ClientMain.main(ClientMain.java:37)