Results 1 to 2 of 2
Thread: MissingReturnStatement
- 08-23-2011, 08:49 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
MissingReturnStatement
I have this code:
When I try to execute method getFromId (from main class), I get error message:Java Code:import java.sql.*; public class Products { private int ProductID; private String name; private String category; private Double price; public void setId(int ProductID) { this. ProductID = ProductID; } public int getId() { return this.ProductID; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setCategory(String category) { this. category = category; } public String getcategory () { return this.category; } public void setPrice(double price) { this.price = price; } public double getCijena() { return this.price; } public Products(int ProductID, String name, String category, Double price) { this.ProductID = ProductID; this.name = name; this.category = category; this.price = price; } public static Product getFromId(int productID) { Connection conn = null; { try { Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection ("jdbc:mysql://localhost/prodaja", "root", ""); System.out.println(conn.isClosed()); } catch(Exception ex) { System.out.println("Connection not established"); } try { Statement st = conn.createStatement(); st.executeQuery("select * from products WHERE ID_product="+productID); ResultSet rs = st.getResultSet(); while (rs.next()) { int IdP = rs.getInt(1); String Pname = rs.getString(2); String Pcategory = rs.getString(3); Double Pprice = rs.getDouble(4); Product p=new Product(IdP, Pname, Pcategory, Pprice); return p; } } catch (SQLException s){ System.out.println("SQL statement not executed!"); } finally { try { if(conn!=null && !conn.isClosed()) conn.close(); System.out.println(conn.isClosed()); } catch(Exception ex) { } } }
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
at sales.Product.getfromId(Product.java:158)
at sales.Sales.main(Sales.java:18)
Java Result: 1
Line 158 is(Product class)
Line 18 is (Sales class)Java Code:public static Product getFromId(int productID) { //line158//
Any suggestions?Java Code:public class Prodaja { /** * @param args the command line arguments */ public static void main(String[] args) { Proizvod.getfromId(1001) //line18//
- 08-23-2011, 09:31 PM #2


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks