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币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Subquery returns more than 1 row
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 table2)
错误代码: 1242 Subquery returns more than 1 row
1. 错误描述1 queries executed, 0 success, 1 errors, 0 warnings查询:SELECT t.id, DATE_FORMAT( t.statisTime, '%Y-%m-%d %H:%i:%s' ) statisTime, (SELECT `id` FROM t_truck_info WHERE id = t.plateId...错误代码: 1242 S
报错java.sql.SQLException: Subquery returns more than 1 row
原因,子查询返回结果大于1,而外层查询使用了等于号,改为in
报错 MYSQL --Subquery returns more than 1 row
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
【MySQL】Subquery returns more than 1 row 解决方案
问题提出:     有如下需求,在同一张表中,当某个字段的值符合一定条件时,修改另一个字段的值。     SQL:update topic set topi_closed = 1 where topi_id = (select topi_id from (select * from topic) as b where now() > topi_stilltime and topi_closed
MYSQL --Subquery returns more than 1 row查询结果多于一行
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
关于mysql错误:Subquery returns more than 1 row
mysql报错:SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row 错误的意思是指子查询结果多于一行。报错如下: 解决方法: 以select * from table1 where table1.colums=(select columns from table2);这个s
[Err] 1242 - Subquery returns more than 1 row
1、错误描述[SQL]SELECT queryStuName(2016010101); [Err] 1242 - Subquery returns more than 1 row2、错误原因BEGIN DECLARE stuName VARCHAR(100); SET stuName = (SELECT stu_name FROM t_student_info WHERE stu_no =
ORA-01427:single-row subquery returns more than one row
今天开发的同事反馈一个问题,该程序已经使用一段时间,在查询昨天的数据时突然报出了错误:                       图1   OR-01427:single-row subquery returns more than one row  异常为:单行子查询返回多行 我得到了该查询页面对应的sql语句:  SELECT  ID,(SELECT NAME FROM TABL
SQL Error: ORA-01427: single-row subquery returns more than one row
http://stackoverflow.com/questions/9970480/updateerror-receiving-error-ora-01427-single-row-subquery-returns-more-than-o