首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataOutputStream条件

DataOutputStream条件
EN

Stack Overflow用户
提问于 2017-05-20 12:06:22
回答 1查看 30关注 0票数 0

我有一个在java中的分配,它将接受来自用户的账号和金额,将添加到数据库MS accecc和它的内容客户端的余额。和服务器端,服务器端将连接到数据库和数据库中的机器记录,如果它找到了,服务器将返回新的余额和利息,它为我工作,但当我使用if else条件时,如果数据没有从新的余额和利息中找到reuten 0,在我的情况下不返回任何东西。服务器端:

代码语言:javascript
复制
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);

}

和客户端:

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2017-05-20 12:10:20

在你的工作案例中,你有:

代码语言:javascript
复制
outs.writeUTF(name);

在您的非工作情况下,您会错过这一点。

因此,在else的情况下,您似乎忘记了将名称写出到流中,从而使客户端感到困惑,因为客户端希望首先读取字符串。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44081791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档