this of course parts of larger code. compile no problem, when call method error
"syntax error near or @ "."" @ position of stmt.executequery(sql).
i appreciate help!
private void component() { try { statement stmt = con.createstatement(); string sql = "select component.*, stock.amount_of_component, component.price component.component_type " + "from component join stock " + "on component.id = stock.component_id " + "order component.component_type"; resultset rs = stmt.executequery(sql); rs.next(); int id = rs.getint("id"); int amount_of_component = rs.getint("amount"); string name = rs.getstring("name"); double price = rs.getdouble("price"); string component_type = rs.getstring("type"); system.out.println(" " + id + amount_of_component + " " + name + " " + price + " " + component_type); } catch (sqlexception err) { system.out.println(err.getmessage()); } }
typo, missing comma in query between component.price , component.component_type :
select component.*, stock.amount_of_component, component.price, component.component_type component join stock on component.id = stock.component_id order component.component_type
edit: read whole result set, put cycle instead of rs.next()
while(result.next()) { int id = rs.getint("id"); int amount_of_component = rs.getint("amount"); string name = rs.getstring("name"); double price = rs.getdouble("price"); string component_type = rs.getstring("type"); system.out.println(" " + id + amount_of_component + " " + name + " " + price + " " + component_type); }
edit2: print header, have manually putting system.out.println(" id amount_of_component name price component_type ");
before while.
Comments
Post a Comment