用JAVA制作ICQ(2)
作者:佚名; 更新时间:2014-12-05
\;//以下告诉客户其注册的号码 PreparedStatement prepare3=c2.prepareCall(sql2); prepare3.clearParameters(); prepare3.setString(1,nickname); ResultSet r2=prepare3.executeQuery(); while(r2.next()){ //out.println(r2.getInt(1)); no=r2.getInt(1); System.out.println(no); } out.println(no); out.println(\ok\);c2.close();//完毕 }catch (Exception e){e.printStackTrace();out.println(\false\);} socket.close(); }//end new //新建用户结束 //以下处理用户查找好友 else if(str.equals(\find\)){ try{ Class.forName(\sun.jdbc.odbc.JdbcOdbcDriver\); Connection c3=DriverManager.getConnection(\jdbc:odbc:javaicq\,\ \,\ \); //以下连接数据库,并且返回其他用户的呢称,性别,籍贯,个人资料等信息 String find=\select nickname,sex,place,ip,email,info from icq\; Statement st=c3.createStatement(); ResultSet result=st.executeQuery(find); while(result.next()){ out.println(result.getString(\nickname\)); out.println(result.getString(\sex\)); out.println(result.getString(\place\)); out.println(result.getString(\ip\)); out.println(result.getString(\email\)); out.println(result.getString(\info\)); }//while end out.println(\over\); ////////GET ICQNO int d,x;boolean y;//以下返回用户的jicq号码,头像号,及是否在线 ResultSet iset=st.executeQuery(\select icqno,pic,status from icq\); while(iset.next()){ d=iset.getInt(\icqno\); out.println(d); x=iset.getInt(\pic\);//pic info out.println(x); y=iset.getBoolean(\status\); if (y){out.println(\1\);} else {out.println(\0\);} //System.out.println(d); } // end send jicqno iset.close(); /////////icqno end c3.close();result.close(); }catch (Exception e){e.printStackTrace();System.out.println(\false\);} //socket.close(); }//end find //查找好友结束 //以下处理用户登录时读取其好友资料 else if(str.equals(\friend\)){ try{ Class.forName(\sun.jdbc.odbc.JdbcOdbcDriver\); Connection c4=DriverManager.getConnection(\jdbc:odbc:javaicq\,\ \,\ \); //以下连接好友表,返回用户的好友名单 String friend=\select friend from friend where icqno=?\; PreparedStatement prepare4=c4.prepareCall(friend); prepare4.clearParameters(); int icqno=Integer.parseInt(in.readLine()); System.out.println(icqno); prepare4.setInt(1,icqno); ResultSet r4=prepare4.executeQuery(); Vector friendno=new Vector();//该矢量保存好友号码 while(r4.next()){ friendno.add(new Integer(r4.getInt(1))); } //read friend info //以下告诉客户其好友的呢称,号码,ip地址,状态,头像,个人资料等信息 out.println(friendno.size()); for(int i=0;i<friendno.size();i++){ String friendinfo=\select nickname,icqno,ip,status,pic,email,info from icq where icqno=?\; PreparedStatement prepare5=c4.prepareCall(friendinfo); prepare5.clearParameters(); prepare5.setObject(1,friendno.get(i)); ResultSet r5=prepare5.executeQuery(); boolean status; while(r5.next()){ out.println(r5.getString(\nickname\)); out.println(r5.getInt(\icqno\)); out.println(r5.getString(\ip\)); status=r5.getBoolean(\status\); if (status)out.println(\1\); else {out.println(\0\);} out.println(r5.getInt(\pic\)); out.println(r5.getString(\email\)); out.println(r5.getString(\info\)); } //while r5.close();}//for//发送完毕 out.println(\over\); System.out.println(\over\); c4.close();r4.close(); }catch (Exception e){e.printStackTrace();System.out.println(\false\);} //socket.close(); }//end friend //读取好友信息完毕 //以下处理用户添加好友 else if(str.equals(\addfriend\)){ System.out.println(\add\); try{ Class.forName(\sun.jdbc.odbc.JdbcOdbcDriver\); Connection c6=DriverManager.getConnection(\jdbc:odbc:javaicq\,\ \,\ \); //连接数据库,根据接受的用户号码及好友号码向好友表添加记录 int friendicqno=Integer.parseInt(in.readLine()); System.out.println(friendicqno); int myicqno=Integer.parseInt(in.readLine()); System.out.println(myicqno); String addfriend=\insert into friend values(?,?)\; PreparedStatement prepare6=c6.prepareCall(addfriend); prepare6.clearParameters(); prepare6.setInt(1,myicqno); prepare6.setInt(2,friendicqno); int r6=0; r6=prepare6.executeUpdate(); if(r6==1) System.out.println(\ok addfrien\); else System.out.println(\false addfriend\); }catch (Exception e){e.printStackTrace();System.out.println(\false\);} //socket.close(); System.out.println(\over addfriend\); }//end addfriend //用户添加好友结束 //add new friend who add me //以下处理其他用户如果加我,我就加他 else if(str.equals(\addnewfriend\)){ System.out.println(\add\); try{ Class.forName(\sun.jdbc.odbc.JdbcOdbcDriver\); Connection c6=DriverManager.getConnection(\jdbc:odbc:javaicq\,\ \,\ \); //连接数据库,根据接受的用户号码及好友号码向好友表添加记录 int friendicqno=Integer.parseInt(in.readLine()); System.out.println(friendicqno); int myicqno=Integer.parseInt(in.readLine()); System.out.println(myicqno); String addfriend=\insert into friend values(?,?)\; PreparedStatement prepare6=c6.prepareCall(addfriend); prepare6.clearParameters(); prepare6.setInt(1,myicqno); prepare6.setInt(2,friendicqno); int r6=0; r6=prepare6.executeUpdate(); if(r6==1) System.out.println(\ok addfrien\); else System.out.println(\false addfriend\); String friendinfo=\select nickname,icqno,ip,status,pic,email,info from icq where icqno=?\; //如果成功,就向用户传递好友的基本信息,比如呢称等 PreparedStatement prepare5=c6.prepareCall(friendinfo); prepare5.clearParameters(); prepare5.setInt(1,friendicqno); ResultSet r5=prepare5.executeQuery(); boolean status; while(r5.next()){ System.out.println(\dsf\); out.println(r5.getString(\nickname\)); out.println(r5.getInt(\icqno\)); out.println(r5.getString(\ip\)); status=r5.getBoolean(\status\); if (status)out.println(\1\); else {out.println(\0\);} out.println(r5.getInt(\pic\)); out.println(r5.getString(\email\)); out.println(r5.getString(\info\)); } //while out.println(\over\); r5.close(); c6.close(); }catch (Exception e){e.printStackTrace();System.out.println(\false\);} System.out.println(\over addnewfriend\); }//end addfriend //结束处理其他用户如果加我,我就加他 //delete friend //以下执行用户删除好友 else if(str.equals(\delfriend\)){ System.out.println(\del\); try{ Class.forName(\sun.jdbc.odbc.JdbcOdbcDriver\); Connection c7=DriverManager.getConnection(\jdbc:od
核心期刊快速发表
Copyright@2000-2030 论文期刊网 Corporation All Rights Reserved.
《中华人民共和国信息产业部》备案号:ICP备07016076号;《公安部》备案号:33010402003207
本网站专业、正规提供职称论文发表和写作指导服务,并收录了海量免费论文和数百个经国家新闻出版总署审批过的具有国内统一CN刊号与国际标准ISSN刊号的合作期刊,供诸位正确选择和阅读参考,免费论文版权归原作者所有,谨防侵权。联系邮箱:256081@163.com