[英]DataOutputStream condition
我在Java中進行了一項分配,它將接受用戶的帳號和金額,並將其添加到數據庫MS accecc的余額中,並且它包含客戶端..和服務器端,服務器端將與數據庫連接並在數據庫中進行記錄如果找到了,服務器將收回新的余額和利息,並且為我工作,但是當我使用if條件時,如果找不到數據,則從新的余額和利息中恢復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);
在您的工作案例中,您有:
outs.writeUTF(name);
在您無法正常工作的情況下,您會錯過這一點。
因此,您似乎忘記了在else
情況下將名稱寫到流中,從而使希望首先讀取字符串的客戶端混亂。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.