2 lulingzhizi lulingzhizi 于 2016.05.11 14:31 提问

出现错误:Subquery returns more than 1 row

这是一个进销存的出入库项目部分,现在问题不知道出在哪里,请各位大虾帮帮忙,帮忙看看

 java.sql.SQLException: Subquery returns more than 1 row
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330)
    at com.sxt.gmms.dao.instorage.InStorageDao.addInStorageAndItem(InStorageDao.java:40)
    at com.sxt.gmms.frame.instorage.instorage.InStorageFrame.actionPerformed(InStorageFrame.java:233)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


这是项目的源代码
/**
 * 商品入库的DAO层
 * 
 * @author Administrator
 * 
 */
public class InStorageDao {

    public void addInStorageAndItem(InStorage inStorage,
            List<InStorageItem> itemList) {
        Connection con = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        try {
            con = DBUtil.getConn();
            // 设置自动提交为false
            con.setAutoCommit(false);
            // 先保存入库单
            String inSql = "insert into iss_in(" + "in_code," + "in_date,"
                    + "in_status," + "emp_id)" + " values(?,?,?,("
                    + "select emp_id from iss_employee "
                    + "where emp_name=?)) ";
            stat = con.prepareStatement(inSql, new String[] { "in_id" });
            stat.setString(1, inStorage.getInCode());
            stat.setDate(2, new java.sql.Date(inStorage.getInDate().getTime()));
            stat.setInt(3, inStorage.getInStatus());
            stat.setString(4, inStorage.getEmp().getEmpName());
            stat.executeUpdate();//出错了???

            // 取得返回的入库单id
            int inId = 0;
            rs = stat.getGeneratedKeys();
            if (rs.next()) {
                inId = rs.getInt(1);
            }
            // 再保存入库明细
            String itemSql = "insert into iss_in_item(" + "in_item_price,"
                    + "in_item_qty," + "in_item_status," + "goods_id,"
                    + "in_id)" + "values(?,?,?,"
                    + "(select goods_id from iss_goods where goods_code =  ?),"
                    + "?)";
            stat = con.prepareStatement(itemSql);
            for (InStorageItem inStorageItem : itemList) {
                stat.setFloat(1, inStorageItem.getInItemPrice());
                stat.setInt(2, inStorageItem.getInItemQty());
                stat.setInt(3, 1);
                stat.setString(4, inStorageItem.getGoods().getGoodsCode());
                stat.setInt(5, inId);
                stat.executeUpdate();
            }
            con.commit();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                con.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        } finally {
            DBUtil.closeConn(con, stat, rs);
        }
    }
}

这是数据库部分,用的是MySQL数据库,请各位大虾帮帮忙!
图片说明

图片说明

1个回答

CSDNXIAOC
CSDNXIAOC   2016.05.11 14:42
已采纳

Subquery returns more than 1 row表示子查询返回了多行数据
例如:
select * from table1 where table1.colums=(select columns from table2)
解决方法
select * from table1 where table1.colums=any(select columns from ......
答案就在这里:Subquery returns more than 1 row
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!