无法在 addProduct 方法中加载创建组件


package com.Foodmart;
import javax.jws.*;
import java.sql.*;
@WebService(name = "FoodMart", serviceName = "FoodMartService", portName = "FoodMartHtt)
public class FoodmartWS {
    ProductDetails prod = new ProductDetails();
    @WebMethod(operationName = "check")
    public boolean Authenticate(String user, String pass) {
        PreparedStatement psmt = null;
        Connection c = null;
        try {
            c = ConnectionDB.getConnection();
            String selectSQL = "select * from Employee where Username=? and Password=?";
            psmt = c.prepareStatement(selectSQL);
            psmt.setString(1, user);
            psmt.setString(2, pass);
            psmt.executeQuery();
            c.close();
            return true;
        } catch (SQLException e) {
            return false;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

在此方法中,添加产品中的错误

    @WebMethod(operationName = "AddProduct")
    public ProductDetails ProdcutAdd(int prodid, double qty) {
        PreparedStatement preparedStatement = null;
        Connection con = null;
        try {
            System.out.println("try");
//here i am not able to create another one connection
            con = ConnectionDB.getConnection();
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Food", "root", "manager1");
            String selectSQL = "select Product_Id,Product_Name,Product_Price,Product_Qty from Products where Product_Id=?;";
            System.out.println("bbefore prepared");
            preparedStatement = con.prepareStatement(selectSQL);
            preparedStatement.setInt(1, prodid);
            System.out.println("before result set");
            ResultSet rs = preparedStatement.executeQuery();
            System.out.println("query Executed");
            rs.next();
            prod.setProductId(rs.getInt("Product_Id"));
            prod.setProductName(rs.getString("Product_Name"));
            prod.setProductPrice(rs.getDouble("Product_Price"));
            prod.setProductQty(rs.getInt("Product_Qty"));
            System.out.println("obj set");
            con.close();
            System.out.println("in" + prod);
            return prod;
        } catch (SQLException e) {
            System.out.println(e);
            return null;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

为什么在获得连接后添加此行:

con = ConnectionDB.getConnection();
//con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Food", "root", "manager1");

因此,只需删除它或评论它。

注意您最终在这里错过了一个"),因此这也会产生问题:

@WebService(name = "FoodMart", serviceName = "FoodMartService", portName = "FoodMartHtt)

希望这能帮助你。

最新更新