1 public static void checkstandLogPage() { 2 System.out.println("■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"); 3 System.out.println("\t 1.登录系统\n"); 4 System.out.println("\t 2.退出\n"); 5 System.out.println("■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"); 6 System.out.println("按0返回上一级"); 7 do { 8 String choice=ScannerInfoString(); 9 String regex="[0-2]"; 10 if(choice.matches(regex)){ 11 int info=Integer.parseInt(choice); 12 switch (info) { 13 case 0: 14 mainpage(); 15 break; 16 case 1: 17 int loginTimes=3; 18 while (loginTimes!=0) { 19 loginTimes--;//获取 20 System.out.println("用户名"); 21 String sName=ScannerInfoString(); 22 System.out.println("密 码"); 23 String sPssWord=ScannerInfoString(); 24 ArrayList<SalesMan> salesManInfo=new SalesManDao().checkstandLog(sName); 25 if(salesManInfo == null || salesManInfo.size() == 0){ 26 System.err.println("\t!!用户名输入有误!!\n"); 27 System.out.println("\n剩余登陆次数:" + loginTimes); 28 }else { 29 SalesMan salesMan=salesManInfo.get(0);// 30 if (sPssWord.equals(salesMan.getsPassWord())) { 31 System.out.println("\t ■ ■ ■ ■ ■ ■ ■ ■ 账户成功登陆 ■ ■ ■ ■ ■ ■ ■ ■ "); 32 shoppingSettlementPage(salesMan.getsId()); 33 } else { 34 System.err.println("\t!!密码错误!!\n"); 35 System.out.println("\n剩余登陆次数:" + loginTimes); 36 } 37 } 38 } 39 System.out.println("■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"); 40 System.err.println("\t!!您已被开除!"); 41 System.exit(1); 42 break; 43 case 2: 44 System.out.println("■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■"); 45 System.out.println("您已经退出系统!"); 46 System.exit(-1); 47 break; 48 default: 49 break; 50 } 51 } 52 System.out.println("输入有误请重新输入!"); 53 } while (true); 54 }
1 public static void shoppingSettlementPage(int salesManSid) { 2 System.out.println("■■■■■■■■■■■■■■■■结算■■■■■■■■■■■■■■■■"); 3 do { 4 System.out.println("按 S 开始购物结算.按 0 返回账户登录界面"); 5 String choiNext=ScannerInfoString(); 6 if("0".equals(choiNext)){ 7 //上一页 8 checkstandLogPage(); 9 }else if ("s".equals(choiNext) || "S".equals(choiNext)) { 10 System.out.println("\n--请输入商品编号或商品名--"); 11 int gid=QueryPrint.querySettlement(); 12 switch (gid) { 13 case -3: 14 break; 15 case -1: 16 System.out.println("售罄!"); 17 break; 18 default: 19 System.out.println("商品编号:"); 20 int shoppingGid=ScannerNum(); 21 ArrayList<Goods> goodsList=new QueryPrint().queryGoodsKey(shoppingGid, null); 22 if(goodsList==null || goodsList.size()==0){ 23 System.out.println("未查询到该商品!"); 24 }else { 25 Goods goods=goodsList.get(0); 26 int gNum=goods.getGnum(); 27 double gPrice=goods.getGprice(); 28 System.out.println("请输入购买数量:"); 29 do { 30 int choicegoodsNum=ScannerNum(); 31 if(choicegoodsNum>gNum){ 32 System.err.println("\t!!仓库储备不足!!"); 33 System.out.println("--请重新输入购买数量--"); 34 }else { 35 double allPrice=Arith.mul(choicegoodsNum, gPrice); 36 System.out.println("\t\t\t 购物车结算\n"); 37 System.out.println("\t\t商品名称\t商品单价\t购买数量\t总价\n"); 38 System.out.println("\t\t" + goods.getGname()+ "\t" + gPrice + " $\t"+ choicegoodsNum + "\t" + allPrice 39 + " $\n"); 40 41 do { 42 System.out.println("确认购买:Y/N"); 43 String chshopping=ScannerInfoString(); 44 if ("Y".equals(chshopping) ||"y".equals(chshopping)) { 45 System.out.println("\n总价:" + allPrice 46 + " $"); 47 System.out.println("\n实际缴费金额"); 48 49 do { 50 double amount=ScannerInfo(); 51 double balance=Arith.sub(amount, allPrice); 52 if(balance<0){ 53 System.err.println("\t!!缴纳金额不足!!"); 54 System.out.println("\n请重新输入缴纳金额($)"); 55 }else { 56 Gsales gSales = new Gsales(goods.getGid(),salesManSid,choicegoodsNum); 57 boolean insert=new GsalesDao().shoppingSettlement(gSales); 58 int goodsNewNum=gNum-choicegoodsNum; 59 Goods newGoods=new Goods(goods.getGid(),goodsNewNum); 60 boolean update = new GoodsDao().updateGoods(3, newGoods); 61 if(update && insert){ 62 System.out.println("找零:"+ balance); 63 System.out.println("\n谢谢光临,欢迎下次惠顾"); 64 }else { 65 System.out.println("!支付失败!"); 66 } 67 shoppingSettlementPage(salesManSid); 68 } 69 } while (true); 70 }else if ("n".equals(chshopping) || "N".equals(chshopping)) { 71 shoppingSettlementPage(salesManSid); 72 } 73 System.out.println("确定购买?"); 74 } while (true); 75 } 76 } while (true); 77 } 78 break; 79 } 80 }else { 81 System.out.println("输入有误!"); 82 } 83 } while (true); 84 }
1 public static int querySettlement() { 2 int gid=-1; 3 ArrayList<Goods> goodsSetList=new GoodsDao().queryGoods(3); 4 if(goodsSetList==null || goodsSetList.size()<=0){ 5 System.out.println("无此商品!"); 6 gid=-3; 7 }else { 8 System.out.println("\t\t\t\t\t商品列表\n\n"); 9 System.out.println("\t商品编号\t\t商品名称\t\t商品价格\t\t商品数量\t\t备注\n"); 10 11 for (int i = 0; i < goodsSetList.size(); i++) { 12 Goods goods=goodsSetList.get(i); 13 if(goods.getGnum()>0){ 14 System.out.print("\t" + goods.getGid() + "\t\t" 15 + goods.getGname() + "\t\t" + goods.getGprice() 16 + "\t\t" + goods.getGnum()); 17 18 if(goods.getGnum()==0){ 19 System.out.println("售罄"); 20 }else if (goods.getGnum()<10) { 21 System.out.println("即将售完(低于十件)"); 22 }else { 23 24 } 25 if(goodsSetList.size()== 1){ 26 gid=goods.getGid(); 27 }else { 28 gid=-2; 29 } 30 } 31 } 32 } 33 return gid; 34 }
但是!当进行到这里
System.out.println("按 S 开始购物结算.按 0 返回账户登录界面"); String choiNext=ScannerInfoString(); if("0".equals(choiNext)){ //上一页 checkstandLogPage(); }else if ("s".equals(choiNext) || "S".equals(choiNext)) { System.out.println("\n--请输入商品编号或商品名--"); int gid=QueryPrint.querySettlement();
我输入商品名称后,它就返回这个结果
--请输入商品编号或商品名--
请输入:
草莓
无此商品!
按 S 开始购物结算.按 0 返回账户登录界面
请输入:
java.sql.SQLException: No value specified for parameter 1
哪里出问题了呢?
你要判断一下输入的值是否为空