lulingzhizi 2016-05-11 06:31 采纳率: 100%
浏览 4965
已采纳

出现错误: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条回答

  • Robot-C 2016-05-11 06: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,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp