📄 servers.java.bak
字号:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class Servers
{
public static void main(String args[])
{ ServerSocket server=null;
Server_thread thread=null;
Socket you=null;
while(true)
{
try{
server=new ServerSocket(4567);
System.out.println("服务器开始运行!");
}
catch(IOException e1){System.out.println("正在监听"+"ERRO:"+e1);}
try{you=server.accept();}
catch(IOException e2){System.out.println("忙!!正在等待客户");}
if(you!=null)
{
new Server_thread(you).start();
}
else {continue;}
}
}
}
class Server_thread extends Thread
{ DataInputStream in=null;
DataOutputStream out=null;
Socket socket;
String s="no",temp=null,temp1=null;
String s1=null,s2=null,s3=null,s4="会员",s5="性别",s6="密码",s7="Email地址",s8="QQ号码",s9="主页",s10="签名";
Connection con;
Statement sql;
ResultSet rs;
Server_thread(Socket t)
{
socket=t;
try
{
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
}
catch(IOException e){}
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e1){}
}
public void run()
{
while(true)
{
while(true)
{
try
{ s1=in.readUTF();
System.out.println(s1);
}
catch(IOException e){}
if(s1!=null)break;
}
if(s1.equals("denglu"))
{
System.out.println("Form denglu");
while(true)
{
try
{ s2=in.readUTF();s3=in.readUTF();
System.out.println("会员名:"+s2);
System.out.println("密码:"+s3);
}
catch(IOException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:stud","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM login");
while(rs.next())
{
if(s2.equals(rs.getString("会员")) && s3.equals(rs.getString("密码")))
{s="yes";}
}
con.close();
}
catch(SQLException e2){}
try
{
out.writeUTF(s);
System.out.println("发送了以下信息:"+s);
}
catch(IOException e2){System.out.println("erro:__"+e2);}
if(s2!=null)break;
}
s1=null;
}
else if(s1.equals("zuche"))
{
System.out.println("客户zuche");
while(true)
{
try
{
s4=in.readUTF();s5=in.readUTF();
s6=in.readUTF();s7=in.readUTF();
s8=in.readUTF();s9=in.readUTF();
s10=in.readUTF();
System.out.println("会员名:"+s4);
System.out.println("性别:"+s5);
System.out.println("密码:"+s6);
System.out.println("Email地址:"+s7);
System.out.println("QQ号码:"+s8);
System.out.println("主页:"+s9);
System.out.println("签名:"+s10);
}
catch(IOException e){}
temp="INSERT INTO student VALUES('"+s4+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"','"+s9+"','"+s10+"')";
temp1="INSERT INTO login VALUES('"+s4.trim()+"','"+s6.trim()+"')";
try{
con=DriverManager.getConnection("jdbc:odbc:stud","","");
sql=con.createStatement();
sql.executeUpdate(temp);
con.close();
con=DriverManager.getConnection("jdbc:odbc:stud","","");
sql=con.createStatement();
sql.executeUpdate(temp1);
con.close();
}
catch(SQLException e2){}
if(s4!="null")break;
}s1=null;
}
else if(s1.equals("zucechenggong"))
{
System.out.println("客户zucechenggong");
try{
con=DriverManager.getConnection("jdbc:odbc:stud","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM student");
while(rs.next())
{
s4=rs.getString(1);s5=rs.getString(2);s6=rs.getString(3);
s7=rs.getString(4);s8=rs.getString(5);s9=rs.getString(6);
s10=rs.getString(7);
}
con.close();
}
catch(SQLException e2){}
try
{ out.writeUTF(s4);out.writeUTF(s5);
out.writeUTF(s6);out.writeUTF(s7);
out.writeUTF(s8);out.writeUTF(s9);
out.writeUTF(s10);
System.out.println("发送了以下信息:"+s4+s5+s6+s7+s8+s9+s10);
}
catch(IOException e){}
s1=null;
}
else {System.out.println("客户离开!");}
try{sleep(5);}
catch(InterruptedException e3)
{
System.out.println("客户不存在");
Thread.currentThread().yield();
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -