How to decrease count getting from user input in java and my sql
How to decrease count getting from user input in java and my sql
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");
};
}
in the above queryTwo i am not able to pass user input roomCount from console instead number is working just fine
is there any alternative method to pass scanner input once the number is entered as i am new in java jdbc i need senior people suggestion
Sample input and output i have added below this is working if i use below query
"select mansion_names,rent,single_rooms-1,double_rooms from mansions where mansion_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
I am trying to pass console input to minus from single_rooms like below it is not working
"select mansion_names,rent,single_rooms-roomCounts,double_rooms from mansions where mansion_names =? ";
i do not have idea how to do this help me if you have suggessions i will try on my own. Thank you...!!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment