⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.java

📁 用户需要注册
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
								i ++;
							}
							rs = stmt.executeQuery("Select number FROM shopcar where name = '"+name +"'and state = '0'");
							while(rs.next())
							{
								s1[j] = rs.getString("number");
								j ++;
							}
							rs = stmt.executeQuery("Select price FROM shopcar where name = '"+name +"'and state = '0'");
							while(rs.next())
							{
								s2[i1] = rs.getString("price");
								i1 ++;
							}
							rs = stmt.executeQuery("Select shopkeepername FROM shopcar where name = '"+name +"'and state = '0'");
							while(rs.next())
							{
								s3[j1] = rs.getString("shopkeepername");
								j1 ++;
							}
							//System.out.println("jingle");
								//sum1 = (Double.parseDouble(s));	
						}
						catch(SQLException e)
						{
							System.out.println(e.getMessage());
						}
						
						try
						{	//返回结果				
							Socket isToClient6 = new Socket("localhost", 2018);
							toClient6 = new PrintWriter(isToClient6.getOutputStream(),true);
							int x = i;
							toClient6.println(String.valueOf(i));
							i = 0;
							j = 0;
							i1 = 0;
							j1 = 0;
							
							for(;i < x;)
							{
								toClient6.println(s[i]);
								toClient6.println(s1[j]);
								toClient6.println(s2[i1]);
								toClient6.println(s3[j1]);
								i ++;
								j ++;
								i1 ++;
								j1 ++;
							}
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}
						toClient6.flush();
				}
				case 14:    //进货
				{
					name = new String(in.readLine());
					String sum = new String(in.readLine());
					String sum1 = new String(in.readLine());
					String sum2 = new String(in.readLine());
					DataOutputStream toClient5 = null;
					double sum3= Double.parseDouble(sum1);
					double sum4 = Double.parseDouble(sum2);
					if(!Query1.select1(sum))//商品不存在,则直接插入goods表
						ChaRu.insertUser(name, sum, sum3,sum4);
					else//否则商品数量叠加
					{
						Connection conn = null;
						Statement stmt = null;
						ResultSet rs=null;
						ResultSet rv=null;
						double s=0.0;
						String v=new String();
						String host="localhost";
						String username="root";
						String password1="111111";
						String database="shoppingmall"; 
						String url = "jdbc:mysql://localhost:3306/shoppingmall";
						try
						{  
							//-------------加载驱动-------------------------   
							Class.forName("org.gjt.mm.mysql.Driver").newInstance();
						}
						catch(Exception e)
						{
							System.out.println("Error loading Mysql Driver!");
						}
						try
						{   
							conn = DriverManager.getConnection(url,username,password1);
							stmt = conn.createStatement();  //Statement对象用于将sql语句发送到数据库中 
							rs = stmt.executeQuery("Select number FROM goods where name = '"+name +"'and goodsname='"+sum +"'");
							while(rs.next())
							{
								s=rs.getDouble("number");
							}
							s+=sum3;
						}
						catch(SQLException e)
						{
							System.out.println(e.getMessage());
						}
						ChaRu.updateGoods(name, sum, s, sum4);//更新数据库
					}
					try
					{	//返回结果				
						Socket isToClient5 = new Socket("localhost", 2016);
						toClient5 = new DataOutputStream(isToClient5.getOutputStream());
						toClient5.writeInt(1);
					}
					catch(IOException ex)
					{
						System.err.println(ex);
					}
					toClient5.flush();
				}
				case 15: 	//商品加入购物车
				{
					name = new String(in.readLine());
					String shopername = new String(in.readLine());
					String goodsname = new String(in.readLine());
					String price = new String(in.readLine());
					double price1 = Double.parseDouble(price);
					String number =  new String(in.readLine());
					double number1 = Double.parseDouble(number);
					DataOutputStream toClient5 = null;
					if(ChaRuCar.insertUser(name, goodsname, number1, price1, shopername, 0))
						result=1;
					else 
						result=0;//库存不够
					try
					{	//返回结果				
						Socket isToClient5 = new Socket("localhost", 2017);
						toClient5 = new DataOutputStream(isToClient5.getOutputStream());
						toClient5.writeInt(result);
						result=1;
					}
					catch(IOException ex)
					{
						System.err.println(ex);
					}
					toClient5.flush();
				}
				case 16:			//店主打烊
				{
					name = new String(in.readLine());
					int state = 0;
					DataOutputStream toClient5 = null;
					if(Query.select(name))
					{
						Change.updateUser(name, state);//修改店主状态
					}
					try
					{					
						Socket isToClient5 = new Socket("localhost", 2014);
						toClient5 = new DataOutputStream(isToClient5.getOutputStream());
						toClient5.writeInt(1);
					}
					catch(IOException ex)
					{
						System.err.println(ex);
					}
					toClient5.flush();
				}
				case 17://输入用户名,找回密码
				{
					name = new String(in.readLine());
					String s = new String();
					if(Query.select(name))//用户名存在
					{
						Connection conn = null;
						Statement stmt = null;
						ResultSet rs=null;
						String host="localhost";
						String username="root";
						String password1="111111";
						String database="shoppingmall"; 
						String url = "jdbc:mysql://localhost:3306/shoppingmall";
						try{  
						   //-------------加载驱动-------------------------   
							Class.forName("org.gjt.mm.mysql.Driver").newInstance();
						  	}catch(Exception e){
						  		System.out.println("Error loading Mysql Driver!");
						  	}
						  	try{   
						  		conn = DriverManager.getConnection(url,username,password1);
						  		System.out.println("Success connect Mysql Database!1"); 
						  		stmt = conn.createStatement();  //Statement对象用于将sql语句发送到数据库中 
						  		rs = stmt.executeQuery("Select question FROM user where name = '"+name +"'");
						  		while(rs.next())
						  		{
						  			s = rs.getString("question").trim();
						  		}
						  		conn.close();
						  	}catch(SQLException e){
						  		System.out.println(e.getMessage());
						  	}
					}
					else 
						result4 = 0;
					try
					{//返回密码提示问题
						PrintWriter toClienta = null;
						Socket isToClienta = new Socket("localhost", 2025);
						//DataOutputStream toClienta = new DataOutputStream(isToClienta.getOutputStream());
						toClienta = new PrintWriter(isToClienta.getOutputStream(),true);
						toClienta.println(result4);
						toClienta.println(s);
						System.out.println(result4);
						result4=1;
					}
					catch(IOException ex)
					{
						System.err.println(ex);
					}						
				}
				case 18://输入密码提示问题答案
				{
					name = new String(in.readLine());
					answer = new String(in.readLine());
					Connection conn = null;
					Statement stmt = null;
					ResultSet rs=null;
					ResultSet rv=null;
					String host="localhost";
					String username="root";
					String password1="111111";
					String database="shoppingmall"; 
					String s=new String();
					String v=new String();
					String url = "jdbc:mysql://localhost:3306/shoppingmall";
					try{  
					   //-------------加载驱动-------------------------   
						Class.forName("org.gjt.mm.mysql.Driver").newInstance();
					  	}catch(Exception e){
					  		System.out.println("Error loading Mysql Driver!");
					  	}
					  	try{   
					  		conn = DriverManager.getConnection(url,username,password1);
					  		System.out.println("Success connect Mysql Database!1"); 
					  		stmt = conn.createStatement();  //Statement对象用于将sql语句发送到数据库中 
					  		rs = stmt.executeQuery("Select answer FROM user where name = '"+name +"'");
					  		while(rs.next())
					  		{
					  			s = rs.getString("answer").trim();
					  		}
					  		if(!s.equals(answer))
					  			result5=-1;
					  		else
					  		{
					  			rv = stmt.executeQuery("Select password FROM user where name = '"+name +"'");
						  		while(rv.next())
						  		{
						  			v=rv.getString("password");
						  		}
					  		}
					  		conn.close();
					  	}catch(SQLException e){
					  		System.out.println(e.getMessage());
					  	}
					  	try 
						{//返回结果
							PrintWriter toClientb = null;
							Socket isToClientb = new Socket("localhost", 2026);
							toClientb = new PrintWriter(isToClientb.getOutputStream(),true);
							toClientb.println(result5);
							toClientb.println(s);
							toClientb.println(v);
							System.out.println(result5);
							result5=1;
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}			
				}
				case 19:	//删除商品
				{
					name = new String(in.readLine());
					String goodsname = new String(in.readLine());
					DataOutputStream toClient5 = null;
					int i=1;
					if(Query1.select1(goodsname))//商品存在
					{
						Connection conn = null;
						Statement stmt = null;
						String host="localhost";
						String username="root";
						String password1="111111";
						String database="shoppingmall"; 
						String url = "jdbc:mysql://localhost:3306/shoppingmall";
						try
						{  
						//-------------加载驱动-------------------------   
							Class.forName("org.gjt.mm.mysql.Driver").newInstance();
						}
						catch(Exception e)
						{
							System.out.println("Error loading Mysql Driver!");
						}
						try
						{   
							conn = DriverManager.getConnection(url,username,password1);
							stmt = conn.createStatement();  //Statement对象用于将sql语句发送到数据库中 
							stmt.executeUpdate("delete FROM goods where name = '"+name +"'and goodsname='"+goodsname +"'");
						}
						catch(SQLException e)
						{
							System.out.println(e.getMessage());
						}
					}
					else i=0;
						try
						{	//返回结果				
							Socket isToClient5 = new Socket("localhost", 2031);
							toClient5 = new DataOutputStream(isToClient5.getOutputStream());
							toClient5.writeInt(i);
							i=1;
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}
						toClient5.flush();
				}
				case 20:       //取消购买
				{
						int r = 1;
						name = new String(in.readLine());
						String shopername = new String(in.readLine());
						String goodsname = new String(in.readLine());
						DataOutputStream toClient4 = null;
						ChaRuCar.deletegoods(name, goodsname, shopername);//恢复商店中商品的数量
						Change1.updateUser(name, shopername,goodsname);//删除购物车中的商品
						try
						{	//返回结果				
							Socket isToClient4 = new Socket("localhost", 2040);
							toClient4 = new DataOutputStream(isToClient4.getOutputStream());
							toClient4.writeInt(r);
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}
						toClient4.flush();
				}
				case 21://关闭窗口时检查购物车
				{
					name = new String(in.readLine());
					DataOutputStream toClient5 = null;
					if(Query2.select(name))//购物车中有商品
						result =-1;
					else result=1;
					try
					{	//返回结果				
						Socket isToClient5 = new Socket("localhost", 2034);
						toClient5 = new DataOutputStream(isToClient5.getOutputStream());
						toClient5.writeInt(result);
						result=1;
					}
					catch(IOException ex)
					{
						System.err.println(ex);
					}
					toClient5.flush();
				}
				case 22:       //议价
				{
						int r = 1;
						name = new String(in.readLine());
						String goodsname = new String(in.readLine());
						String shopername = new String(in.readLine());
						String price = new String(in.readLine());
						double price1 = Double.parseDouble(price);
						String sum = new String(in.readLine());
						int sum1 = Integer.parseInt(sum);
						DataOutputStream toClient4 = null;
						//if()
						if(Query2.select(name))//若购物车中存在该商品,则修改价格
						{
							ChaRuCar.deletegoods(name, goodsname, shopername);//恢复商店中商品的数量
							Change1.updateUser(name, shopername,goodsname);//删除购物车中原有商品
							ChaRuCar.insertUser(name, goodsname,sum1, price1, shopername, 0);//新价格加入购物车
						}
						else
						{
							ChaRuCar.insertUser(name, goodsname,sum1, price1, shopername, 0);
						}
						try
						{	//返回结果				
							Socket isToClient4 = new Socket("localhost", 2055);
							toClient4 = new DataOutputStream(isToClient4.getOutputStream());
							toClient4.writeInt(1);
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}
						toClient4.flush();
				}
				}
			}		
			catch(IOException ex)
			{
				System.out.println(ex);
			}
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Server frame = new Server();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -