当前位置: 首页 > 知识库问答 >
问题:

不支持左操作数类型为“VARCHAR”和右操作数类型为“VARCHAR”的“”运算符

越涛
2023-03-14

请看下面的代码。我使用Apache Derby作为嵌入式数据库

public List getDetails(String name)
    {
        List details = new ArrayList();

        name = name.replaceAll("\\s+", "").toUpperCase();
        try
        {
            createConnection();

            PreparedStatement ps = con.prepareStatement("select * from PhoneData where upper(rtrim(NULLIF(names,''))) + upper(rtrim(NULLIF(middleName,''))) +  upper(rtrim(NULLIF(lastName,'')))=?");
            ps.setString(1, name);

            ResultSet rs = ps.executeQuery();

          // System.out.println("First Mobile Number: "+rs.getInt(3));
            while(rs.next())
            {
                details.add(rs.getInt(1));
                details.add(rs.getString(2));
                details.add(rs.getString(3));
                details.add(rs.getString(4));
                details.add(rs.getString(5));
                details.add(rs.getString(6));
                details.add(rs.getString(7));
                details.add(rs.getString(8));
                details.add(rs.getString(9));
                details.add(rs.getString(10));
                details.add(rs.getString(11));
                details.add(rs.getString(12));
                details.add(rs.getString(13));
                details.add(rs.getString(14));
            }

            for(int i=0;i<details.size();i++)
            {
                System.out.println(details.get(i));
            }
            System.out.println("------------Database handler Done------------");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            closeConnection();
        }

        return details;
    }

此代码出现以下错误

java.sql.SQLSyntaxErrorException: The '+' operator with a left operand type of 'VARCHAR' and a right operand type of 'VARCHAR' is not supported.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
    at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
    at normal.DatabaseHandler.getDetails(DatabaseHandler.java:150)
    at normal.UpdateDeleteForm$DetailsLoader.itemStateChanged(UpdateDeleteForm.java:417)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1225)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1282)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:1329)
    at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:94)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.java:578)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
    at java.awt.Component.processMouseEvent(Component.java:6504)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
    at java.awt.Component.processEvent(Component.java:6269)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4860)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.sql.SQLException: The '+' operator with a left operand type of 'VARCHAR' and a right operand type of 'VARCHAR' is not supported.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
    ... 56 more
Caused by: ERROR 42Y95: The '+' operator with a left operand type of 'VARCHAR' and a right operand type of 'VARCHAR' is not supported.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.sql.compile.BaseTypeCompiler.resolveArithmeticOperation(Unknown Source)
    at org.apache.derby.impl.sql.compile.BinaryArithmeticOperatorNode.bindExpression(Unknown Source)
    at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(Unknown Source)
    at org.apache.derby.impl.sql.compile.BinaryArithmeticOperatorNode.bindExpression(Unknown Source)
    at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(Unknown Source)
    at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindExpression(Unknown Source)
    at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
    at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
    at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
    at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
    at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
    ... 50 more
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at normal.UpdateDeleteForm$DetailsLoader.itemStateChanged(UpdateDeleteForm.java:435)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1225)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1282)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:1329)
    at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:94)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.java:578)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
    at java.awt.Component.processMouseEvent(Component.java:6504)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
    at java.awt.Component.processEvent(Component.java:6269)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4860)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 7 seconds)

在这里,我试图做的是,获取全名,它作为FirstName、MiddleName和LastName存储在数据库中。

示例:名字-彼得,中间名-梅塔,姓氏-约翰逊

然后我试着得到“彼得·梅塔·约翰逊”。这就是为什么我使用运算符将值合并到3列中。

为什么我得到这个错误?这在MSSQL Server中有效,但在Derby中失败。请帮助!

共有2个答案

罗梓
2023-03-14

根据德比文件(http://db.apache.org/derby/docs/10.4/ref/rrefsqlj40899.html),Derby中的连接运算符类似于Oracle,因此将“”s替换为“||”。

颛孙英才
2023-03-14

在Derby中,字符串连接运算符不是but||

http://db.apache.org/derby/docs/10.2/ref/rrefsqlj40899.html

 类似资料:
  • 问题内容: 每当我运行这个程序我都会得到这个 我该怎么做才能将pyc除以tpy? 问题答案: 通过将它们变成整数: 在python 3中,该函数返回一个字符串。总是。这是对Python 2的更改;该功能已重命名为。

  • 我目前正在进行客房预订工作,在那里我成功地获得了在特定日期预订的房间数量。我很难从总房间数中减去已经预订的房间数。它一直告诉我,“$No_of_Rooms”是一个数组,我无法从总房间数中减去它。我有一个错误“致命错误:不支持的操作数类型…”。 有人能指导我吗,我刚刚开始学习php。我看了很多有这种错误的线程,但仍然没有类似我的。

  • 我正在为我的小型数据科学项目计算线性回归。 当将list(Dictionary.values())传递到我得到的类中时 回溯(最近的调用为last):文件“C://users/paweé/documents/projects vscode/worldbankdatakeras/tests.py”,第41行,在graph.plot_graph_renewable_electricity_status

  • 问题内容: 我试图像这样制作垂直的seaborn boxplot 我得到 我写东方 并得到 但 作品coreect!怎么了? 问题答案: 对于Seaborn的箱形图,在水平和垂直对齐方式之间切换时,请务必注意x轴和y轴的分配: 混淆列会导致seaborn尝试计算分类数据框中的摘要统计信息,这肯定会失败。

  • 我有以下代码。我知道它既长又复杂,但在我的笔记本电脑上运行需要1.5分钟。如果您能帮助我找到最后导致错误的问题-绘图部分,我将不胜感激。我在Google上没有找到与此错误消息相关的任何内容: QuadMesh和Float的不支持操作数类型 在绘图部分,我尝试了多种形式。它失败于: 在以下情况下失败: 我没有办法在那里介绍什么。 非常感谢。

  • 问题内容: 我是python(PYTHON 3.4.2)的新手,我正在尝试制作一个可进行加法和除法运算的程序,以查找用户输入的平均值或均值,但我不知道如何添加数字接收。 当我在命令提示符下打开程序时,它接受我输入的数字,并且如果我使用打印功能,也将打印它,但不会将数字加起来。 我收到此错误: 我的代码如下: 任何帮助将不胜感激。 问题答案: 将输入作为字符串 您要告诉用户使用逗号分隔输入,因此需要