我有一个在java中的分配,它将接受来自用户的账号和金额,将添加到数据库MS accecc和它的内容客户端的余额。和服务器端,服务器端将连接到数据库和数据库中的机器记录,如果它找到了,服务器将返回新的余额和利息,它为我工作,但当我使用if else条件时,如果数据没有从新的余额和利息中找到reuten 0,在我的情况下不返回任何东西。服务器端:
while(true){
cli = myserver.accept();
DataInputStream ins = new DataInputStream(cli.getInputStream());
DataOutputStream outs = new DataOutputStream(cli.getOutputStream());
int newbalance;
double interst;
if(account == fromdb )
{
//here it work and fine .
String name = rs.getString(3);
outs.writeUTF(name);
newbalance = (rs.getInt(4))+amount;
interst = (newbalance * 0.02);
outs.writeInt(newbalance);
outs.flush();
outs.writeDouble(interst);
}else{
//here it not work.
outs.writeInt(0);
outs.flush();
outs.writeDouble(0);
}和客户端:
String name = ins.readUTF();
System.out.println(name+" your detiels: ");
int b = ins.readInt();
System.out.println("the new balanec is: "+ b);
double interst = ins.readDouble();
System.out.println("the interst is: "+ interst);发布于 2017-05-20 12:10:20
在你的工作案例中,你有:
outs.writeUTF(name);在您的非工作情况下,您会错过这一点。
因此,在else的情况下,您似乎忘记了将名称写出到流中,从而使客户端感到困惑,因为客户端希望首先读取字符串。
https://stackoverflow.com/questions/44081791
复制相似问题