未捕获的 SoapFault 异常:[soapenv:Server] 在结果集开始之前
Uncaught SoapFault exception: [soapenv:Server] Before start of result set
我正在为电子商务网站开发一个 Web 服务,我正在将所有基于 supplier_id 的产品从 java 返回到 php 客户端,但它给了我这个错误
Fatal error: Uncaught SoapFault exception: [soapenv:Server] Before start of result set in C:\wamp\www\eshop\viewProductsSupplier.php:194 Stack trace: #0 C:\wamp\www\eshop\viewProductsSupplier.php(194): SoapClient->__soapCall('viewProducts', Array) #1 {main} thrown in C:\wamp\www\eshop\viewProductsSupplier.php on line 194
我已经尝试检查查询是否执行,但一切正常
//php代码
$soapclient = new SoapClient('http://localhost:8090/Eshop_ecommerce/services/Eshop_ecommerce?wsdl', ['trace' => 1]);
session_start();
$id=array('id'=>@$_SESSION['supplierId']);
$response=$soapclient->__soapCall("viewProducts",$id);
if (isset($response->Name))
{
print $response;
}
else
{
print "Data is null";
}
//Java代码
ViewProductsResponse res = new ViewProductsResponse();
Class.forName(driver);
conn = DriverManager.getConnection(url,username,password);
stmt = conn.createStatement();
String Query=null;
String in=viewProducts.getViewProductsRequest();
if(!in.isEmpty())
{
Query="SELECT * FROM product";
}
else
{
Query="SELECT * FROM product WHERE product_supplier_id='"+viewProducts.getViewProductsRequest()+"'";
}
ProductArray pa=new ProductArray();
ResultSet result= stmt.executeQuery(Query);
//System.out.println(result);
while(result.next())
{
Product p= new Product();
//System.out.println(result.getString("product_id"));
p.setId(result.getString("product_id"));
p.setName(result.getString("product_name"));
p.setPrice(result.getString("product_price"));
p.setStock(result.getString("product_stock"));
String supplierNameQuery="SELECT supplier_id,supplier_name FROM supplier WHERE supplier_id='"+result.getString("product_supplier_id")+"'";
ResultSet resultSupplierName = stmt.executeQuery(supplierNameQuery);
p.setSupplierName(resultSupplierName.getString("supplier_name"));
String catQuery="SELECT * FROM product_category WHERE category_id='"+result.getString("product_category_id")+"'";
ResultSet resCat= stmt.executeQuery(catQuery);
p.setCategoryName(resCat.getString("category_name"));
pa.setProduct(p);
res.setProducts(pa);
}
//res.setViewProductsResponse("Data Entered");
return res;
我希望它打印所有生成的产品
一个ResultSet returned from Statement#executeQuery is positioned before the first row (see linked-in JavaDoc). In order for such ResultSet
to point to the first row it needs re-positioned to it, for example using the next()方法。这是针对外部 SELECT
而不是针对两个内部的。此外,需要检查来自 next()
调用的 return 值,以查看 ResultSet
.
中是否有任何行
这可以像这样实现:
if(resultSupplierName.next()) {
p.setSupplierName(resultSupplierName.getString("supplier_name"));
}
if(resCat.next()) {
p.setCategoryName(resCat.getString("category_name"));
}
请注意,发布的代码还有其他未解决的问题,例如 JDBC 资源未关闭。我强烈建议查看 JEE 或 Spring(假设代码显然在应用程序服务器中运行)或至少在 this. Further is the code prone to SQL injection
我正在为电子商务网站开发一个 Web 服务,我正在将所有基于 supplier_id 的产品从 java 返回到 php 客户端,但它给了我这个错误
Fatal error: Uncaught SoapFault exception: [soapenv:Server] Before start of result set in C:\wamp\www\eshop\viewProductsSupplier.php:194 Stack trace: #0 C:\wamp\www\eshop\viewProductsSupplier.php(194): SoapClient->__soapCall('viewProducts', Array) #1 {main} thrown in C:\wamp\www\eshop\viewProductsSupplier.php on line 194
我已经尝试检查查询是否执行,但一切正常
//php代码
$soapclient = new SoapClient('http://localhost:8090/Eshop_ecommerce/services/Eshop_ecommerce?wsdl', ['trace' => 1]);
session_start();
$id=array('id'=>@$_SESSION['supplierId']);
$response=$soapclient->__soapCall("viewProducts",$id);
if (isset($response->Name))
{
print $response;
}
else
{
print "Data is null";
}
//Java代码
ViewProductsResponse res = new ViewProductsResponse();
Class.forName(driver);
conn = DriverManager.getConnection(url,username,password);
stmt = conn.createStatement();
String Query=null;
String in=viewProducts.getViewProductsRequest();
if(!in.isEmpty())
{
Query="SELECT * FROM product";
}
else
{
Query="SELECT * FROM product WHERE product_supplier_id='"+viewProducts.getViewProductsRequest()+"'";
}
ProductArray pa=new ProductArray();
ResultSet result= stmt.executeQuery(Query);
//System.out.println(result);
while(result.next())
{
Product p= new Product();
//System.out.println(result.getString("product_id"));
p.setId(result.getString("product_id"));
p.setName(result.getString("product_name"));
p.setPrice(result.getString("product_price"));
p.setStock(result.getString("product_stock"));
String supplierNameQuery="SELECT supplier_id,supplier_name FROM supplier WHERE supplier_id='"+result.getString("product_supplier_id")+"'";
ResultSet resultSupplierName = stmt.executeQuery(supplierNameQuery);
p.setSupplierName(resultSupplierName.getString("supplier_name"));
String catQuery="SELECT * FROM product_category WHERE category_id='"+result.getString("product_category_id")+"'";
ResultSet resCat= stmt.executeQuery(catQuery);
p.setCategoryName(resCat.getString("category_name"));
pa.setProduct(p);
res.setProducts(pa);
}
//res.setViewProductsResponse("Data Entered");
return res;
我希望它打印所有生成的产品
一个ResultSet returned from Statement#executeQuery is positioned before the first row (see linked-in JavaDoc). In order for such ResultSet
to point to the first row it needs re-positioned to it, for example using the next()方法。这是针对外部 SELECT
而不是针对两个内部的。此外,需要检查来自 next()
调用的 return 值,以查看 ResultSet
.
这可以像这样实现:
if(resultSupplierName.next()) {
p.setSupplierName(resultSupplierName.getString("supplier_name"));
}
if(resCat.next()) {
p.setCategoryName(resCat.getString("category_name"));
}
请注意,发布的代码还有其他未解决的问题,例如 JDBC 资源未关闭。我强烈建议查看 JEE 或 Spring(假设代码显然在应用程序服务器中运行)或至少在 this. Further is the code prone to SQL injection