如何在java和mysql中通过从控制台传递用户输入来减少计数

bq3bfh9z  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(153)
public void bookRooms(){
try{
System.out.println("Enter rooms to book ");
        int roomCount = scan.nextInt();
        String queryTwo = "select mansion_names,rent,single_rooms-1,double_rooms from mansions where mansion_names =?  ";
        // above query i am not able to pass user input roomCount from console instead number is working
        PreparedStatement ps2 = con.prepareStatement(queryTwo);
        ps2.setString(1, mName);
        ResultSet rs2 = ps2.executeQuery();
        while(rs2.next()){
            System.out.println(" "+rs2.getString(1)+" "+rs2.getInt(2)+" "+rs2.getInt(3)+" "+rs2.getInt(4));//+" "+rs.getInt(4)+" "+rs.getString(5)+" "+rs.getInt(6)+" "+rs.getInt(7));
        }
        con.close();
    }catch(Exception e){
        System.out.println("error");
    };
}

在上面的查询中,我无法从控制台传递用户输入roomcount,相反,数字工作正常。输入数字后是否有其他方法传递扫描仪输入?因为我是java jdbc新手,我需要高级人员建议
我在下面添加的示例输入和输出如果我使用下面的查询“select mansions\u names,rent,single\u rooms-1,double\u rooms from mansions where mansions\u names=?”,这是有效的;

Enter mansion name to book 
Shanthi
 mansion_names rent single_rooms double_rooms
 Shanthi 3500 3 3
Enter rooms to book 
1
 Shanthi 3500 2 3

我正试图通过控制台输入到负从单人房像下面它不工作
“从豪宅中选择豪宅名称、租金、单人房-房间数、双人房,其中豪宅名称=?”;
我不知道如何做到这一点,如果你有建议,我会自己试试。谢谢您。。。!!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题