Hallo Leute,
beschäftige mich gerade mit der Webservice in Java leider habe ich 2 Query, die glaube ich, nicht richtig funktionieren, könnte bestimmt jemandem hier mir weiter helfen.
Hier ist die Methode zum Update
Hier ist die Methode zum Delete
beschäftige mich gerade mit der Webservice in Java leider habe ich 2 Query, die glaube ich, nicht richtig funktionieren, könnte bestimmt jemandem hier mir weiter helfen.
Hier ist die Methode zum Update
Java:
@WebMethod(operationName = "updateProduct")
public int updateProduct(@WebParam(name = "name") String name, @WebParam(name = "isPrice") double isPrice, @WebParam(name = "isD") boolean isD, @WebParam(name = "isDescription") String isDescription) {
Products newEntry = new Products();
newEntry.setName(name);
newEntry.setPrice(isPrice);
newEntry.setD(isD);
newEntry.setDescription(isDescription);
int iRet = dbConn.updateProduct(newEntry);
return 0;
}
Java:
public int updateProduct(products newEntry){
Connection conn = null;
Statement stmt = null;
try{
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
String sql;
sql = "UPDATE `products` SET (`name`, `price`, `d`, `description`) VALUES (newEntry.getName(), newEntry.getPrice(), newEntry.getD(), newEntry.getDescription() ) WHERE `id` = id";
stmt.execute(sql);
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
} catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
return 0;
}
Hier ist die Methode zum Delete
Java:
@WebMethod(operationName = "deleteProduct")
public int deleteProduct(@WebParam(name = "id") int id) {
Products newEntry = new Products();
newEntry.setName(id);
int iRet = dbConn.deleteProduct(newEntry);
return 0;
}
Java:
public int deleteProduct(Products newEntry){
Connection conn = null;
Statement stmt = null;
try{
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
String sql;
sql = "DELETE FROM `Products` WHERE `id`= getId()";
stmt.execute(sql);
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
} catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
return 0;
}