java mysql连接两张表_java连接数据库对两张表进行查询对比的小项目

下面是客户端的启动代码public static void main(String[] args) throws UnknownHostException, IOException {// TODO Auto-generated method stub//获取配置文件Properties pro = new Properties();pro.load(new FileInputStream("fr...
摘要由CSDN通过智能技术生成

下面是客户端的启动代码

public static void main(String[] args) throws UnknownHostException, IOException {

// TODO Auto-generated method stub

//获取配置文件

Properties pro = new Properties();

pro.load(new FileInputStream("freshbin/freshbinIP.properties"));

//通过配置文件中的ip与端口port连接server服务端

String ip = pro.getProperty("ip");

int port = Integer.parseInt(pro.getProperty("port"));

Socket s = new Socket(ip, port);

//创建一个客户端的读与写对象

ClientInputStream inputThread = new ClientInputStream(s);

ClientOutputStream outputThread = new ClientOutputStream(s);

//inputThread.setPriority(1);

//outputThread.setPriority(10);

//启动客户端读与写的线程

inputThread.start();

outputThread.start();

}

下面是客户端发送类中的线程run方法的代码

OutputStream os = null;

Scanner sc = null;

try {

os = this.socket.getOutputStream();

sc = new Scanner(System.in);

while (true) {

//发送请求信息(查询或者更新)

String message = sc.nextLine();

os.write(message.getBytes());

os.flush();

下面是客户端接收类的线程的run方法的代码

InputStream is = null;

try {

is = this.socket.getInputStream();

byte[] buffer = new byte[1024];

int len = 0;

String message = null;

while (-1 != (len = is.read(buffer))) {

//把从服务端接收到的信息打印在控制台

message = new String(buffer, 0, len);

String s = "服务器端:" + message;

System.out.println(s);

下面是服务端的启动代码

public static void main(String[] args) throws IOException {

//获取配置文件

Properties pro = new Properties();

pro.load(new FileInputStream("freshbin/freshbinIP.properties"));

//通过配置文件中的ip与端口port连接server服务端

int port = Integer.parseInt(pro.getProperty("port"));

ServerSocket ss = new ServerSocket(port);

//进行监听

Socket s = ss.accept();

//创建一个服务端的读与写对象

ServerInputStream inputThread = new ServerInputStream(s);

ServerOutputStream outputThread &#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值