【问题标题】:SQL Exception: Table does not exist when accessed using SOAP serviceSQL 异常:使用 SOAP 服务访问时表不存在
【发布时间】:2014-10-09 14:59:13
【问题描述】:

我在嵌入式模式下使用 Derby 数据库。我编写了一个带有 main() 函数的 CreateDB 类,该函数在表中创建/插入/选择。工作正常。(我在项目构建路径中有必要的 jar 文件:))

但是,当我使用相同的数据库和表在我的 Soap Web 服务中选择行时,它给我的错误是表不存在。这是代码: 对于 CreateDB(工作得很好)

package com.myShop.www.ShipmentService;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class CreateDB {
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static final String JDBC_URL = "jdbc:derby:Shipment_DB;create=true"; 
public static void main(String[] args) throws SQLException, ClassNotFoundException {
    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(JDBC_URL);
    String SQLString = "CREATE TABLE SHPMTTYPAV_TBL1(" +
            "SHPMTID INT NOT NULL, " +
            "NAME VARCHAR(30) NOT NULL, " +
            "DESCR VARCHAR(45) NOT NULL, " +
            "MINCOST DOUBLE NOT NULL, " +
            "COSTPEROUNCE DOUBLE NOT NULL, " +
            "ESTDLVYDAYS INT NOT NULL, " +
            "PRIMARY KEY(SHPMTID))";

    connection.createStatement().execute((SQLString));
    String insertSQL = "INSERT INTO SHPMTTYPAV_TBL1 VALUES(5, 'Priority Mail', 'Any item can be shipped', 5, .02, 1)";
    connection.createStatement().execute(insertSQL);

    // invoke sql query
    String selectSQL = "SELECT * From SHPMTTYPAV_TBL1";

    Statement prepStmt = connection.createStatement();

    ResultSet rs = prepStmt.executeQuery(selectSQL);
    while (rs.next()){
        System.out.println(rs.getInt("SHPMTID") + rs.getString("NAME") + rs.getString("DESCR") + rs.getDouble("MINCOST") + " " + rs.getDouble("COSTPEROUNCE")); 
    }
}
}

SOAP 服务实现类中的代码:- 找不到表的错误

public class ShipmentServiceBindingImpl implements ShipmentServicePortType{
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static final String JDBC_URL = "jdbc:derby:Shipment_DB;create=true";
public com.myShop.www.ShipmentService.ItemsInOrderResponseType[] getShpmtTps_Csts_DlvyDts(com.myShop.www.ShipmentService.ItemsInOrderType[] itemsInOrder) throws java.rmi.RemoteException, ClassNotFoundException, SQLException {
    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(JDBC_URL);

    String selectSQL = "SELECT * From SHPMTTYPAV_TBL1";

    Statement prepStmt = connection.createStatement();
    ResultSet rs = prepStmt.executeQuery(selectSQL);

    int len = itemsInOrder.length;
    ItemsInOrderResponseType[] res = new ItemsInOrderResponseType[len];


    for(int i = 0; i < len; i++){
        rs.next();
        res[i] = new ItemsInOrderResponseType();
        res[i].setShpmtID(rs.getInt("SHPMTID"));
        res[i].setShpmtName(rs.getString("NAME"));
        res[i].setCost(rs.getDouble("COSTPEROUNCE"));
        res[i].setEstDlvyDays(rs.getDouble("MINCOST"));
    }
    if (rs != null) rs.close();
    if (prepStmt != null) prepStmt.close();
    if (connection != null) connection.close();
    return res;
}

}

【问题讨论】:

    标签: sql soap derby


    【解决方案1】:

    尝试在这两种情况下将 derby.system.home 设置为相同的值。如果未设置 Derby 使用当前目录,这两种情况可能不同。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多