有哪位搞手可以帮我呀,, (100分)

  • 主题发起人 主题发起人 gbman
  • 开始时间 开始时间
G

gbman

Unregistered / Unconfirmed
GUEST, unregistred user!
client.java
import java.net.*;
import java.io.*;
public class client
{
public static void main(String[] args)
{
Socket clientSocket;
BufferedReader br1,br2;
PrintStream ps;
String username,passwords,email,homepage,moneys,inString;
try
{
clientSocket=new Socket("china-zzkdn8t9z.",8886);
br1=new BufferedReader(new InputStreamReader(System.in));
br2=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
ps=new PrintStream(clientSocket.getOutputStream());

System.out.print("请输入用户姓名(必输项,最多20个字符):");
username=br1.readLine();
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入密码(必输项,最多20个字符):");
passwords=br1.readLine();
ps.println(passwords);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入电子邮件地址(必输项,最多30个字符):");
email=br1.readLine();
ps.println(email);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入个人主页(必输项,最多50个字符):");
homepage=br1.readLine();
ps.println(homepage);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入金额(必输项,只能是数字):");
moneys=br1.readLine();
ps.println(moneys);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

br1.close();
br2.close();
ps.close();
clientSocket.close();
}catch(Exception e)
{
System.out.println(e);
}
}
}
server.java
import java.net.*;
import java.io.*;
import java.sql.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
import java.util.Properties;
public class server
{
public static void main(String[] args) throws Exception
{
ServerSocket serverSocket;
Socket clientSocket;
BufferedReader br;
PrintStream ps;
String username,passwords,email,homepage,moneys,outString,sql;


Properties p = new Properties();
p.put("databasename","userinfo");
p.put("user","liupeng");
p.put("password","");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://china-zzkdn8t9z.:8888",p);
Statement stmt=con.createStatement();

serverSocket=new ServerSocket(8886);
clientSocket=serverSocket.accept();

br=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
ps=new PrintStream(clientSocket.getOutputStream());

username=br.readLine();
outString="/t/t/t/t/t你输入的姓名是:"+username;
ps.print(outString);
ps.flush();

passwords=br.readLine();
outString="/t/t/t/t/t你输入的密码是:"+passwords;
ps.println(outString);
ps.flush();

email=br.readLine();
outString="/t/t/t/t/t你输入的邮件地址是:"+email;
ps.println(outString);
ps.flush();

homepage=br.readLine();
outString="/t/t/t/t/t你输入的主页是:"+homepage;
ps.println(outString);
ps.flush();

moneys=br.readLine();
outString="/t/t/t/t/t你输入的金额是:"+moneys;
ps.println(outString);
ps.flush();

sql="insert info userinfo values(/'"+username+"/',/'"+passwords+"/',/'"+email+"/',/'"+homepage+"/',sysdate,"+moneys+")";
int ret=stmt.executeUpdate(sql);

br.close();
ps.close();

stmt.close();
con.close();
}
}
 
1.>>System.out.print("请输入用户姓名(必输项,最多20个字符):");
>>username=br1.readLine();
>>ps.flush();
中,改成
System.out.print("请输入用户姓名(必输项,最多20个字符):");
username=br1.readLine();
ps.println(username);
ps.flush();
 
楼上的说的是,还有一个错误,在server.java中
代码:
username=br.readLine();
outString="/t/t/t/t/t你输入的姓名是:"+username;
ps.[red]print[/red](outString);
ps.flush();
应当是println,否则client的br2.readLine()读不到,就僵在那里了
 
谢谢你们二个的回答。。但我改了还是不行。。client还是没反应。。头都大了。。
 
把代码(新的)贴出来,全部贴出来
 
奇怪[?]我这里运行的好好的啊,我把改过的文件再贴一遍
//client.java
import java.net.*;
import java.io.*;
public class client{
public static void main(String[] args){
Socket clientSocket;
BufferedReader br1,br2;
PrintStream ps;
String username,passwords,email,homepage,moneys,inString;
try{
clientSocket=new Socket("china-zzkdn8t9z.",8886);
br1=new BufferedReader(new InputStreamReader(System.in));
br2=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
ps=new PrintStream(clientSocket.getOutputStream());

System.out.print("请输入用户姓名(必输项,最多20个字符):");
username=br1.readLine();
ps.println(username);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入密码(必输项,最多20个字符):");
passwords=br1.readLine();
ps.println(passwords);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入电子邮件地址(必输项,最多30个字符):");
email=br1.readLine();
ps.println(email);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入个人主页(必输项,最多50个字符):");
homepage=br1.readLine();
ps.println(homepage);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

System.out.print("请输入金额(必输项,只能是数字):");
moneys=br1.readLine();
ps.println(moneys);
ps.flush();

inString=br2.readLine();
System.out.println(inString);

br1.close();
br2.close();
ps.close();
clientSocket.close();
}catch(Exception e){
System.out.println(e);
}
}
}///~
//server.java
import java.net.*;
import java.io.*;
import java.sql.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
import java.util.Properties;
public class server{
public static void main(String[] args) throws Exception{
ServerSocket serverSocket;
Socket clientSocket;
BufferedReader br;
PrintStream ps;
String username,passwords,email,homepage,moneys,outString,sql;


/*
Properties p = new Properties();
p.put("databasename","userinfo");
p.put("user","liupeng");
p.put("password","");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://china-zzkdn8t9z.:8888",p);
Statement stmt=con.createStatement();
*/

serverSocket=new ServerSocket(8886);
clientSocket=serverSocket.accept();

br=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
ps=new PrintStream(clientSocket.getOutputStream());

username=br.readLine();
outString="/t/t/t/t/t你输入的姓名是:"+username;
ps.println(outString);
ps.flush();

passwords=br.readLine();
outString="/t/t/t/t/t你输入的密码是:"+passwords;
ps.println(outString);
ps.flush();

email=br.readLine();
outString="/t/t/t/t/t你输入的邮件地址是:"+email;
ps.println(outString);
ps.flush();

homepage=br.readLine();
outString="/t/t/t/t/t你输入的主页是:"+homepage;
ps.println(outString);
ps.flush();

moneys=br.readLine();
outString="/t/t/t/t/t你输入的金额是:"+moneys;
ps.println(outString);
ps.flush();

/*
sql="insert info userinfo values(/'"+username+"/',/'"+passwords+"/',/'"+email+"/',/'"+homepage+"/',sysdate,"+moneys+")";
int ret=stmt.executeUpdate(sql);
*/

br.close();
ps.close();

/*
stmt.close();
con.close();
*/
}
}///~
其中数据库那段我注释掉了
 
我看是连数据库是不是没写对???
 
我总算搞出来了——不过要谢谢大家……。要源码的找我,,
 
后退
顶部