简体   繁体   中英

Passing parameter to Java Method then using that parameter in SQL Query Statement

So the idea is that i can send an amount of bedrooms(int) as a parameter to a Java method which will use that int parameter in an SQL statement that returns all houses in the database with X amount of bedrooms.

public void displayProperty(int bedrooms) throws SQLException{

ResultSet rs = Stmt.executeQuery("select * from PropertySale where bedroomsAmount = 'bedrooms' ;");

How exactly do i pass that parameter straight through to the statement?

ResultSet rs = Stmt.executeQuery("select * from PropertySale where bedroomsAmount =" + bedrooms + ";");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM