public double getPrice(String name) throws SQLException {
TechnoRepository repo = TechnoRepository.getInstance();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select price from products where name = '?';");
if(rs.next())
return rs.getDouble("price");
return 0;
}
Main class :
TechnoRepository repo = TechnoRepository.getInstance();
double price = repo.getPrice("water");
System.out.printf("%.2f",price);
Result is 0.0, not the right one