2014-02-05 67 views
2

我試圖尋找一些文本值一個CLOB類型的列另一個德比數據類型,SQL代碼:德比CLOB例外建議我沒有長度設置

SELECT * FROM APP.Stuff where MyClob='sometext' 

當執行我得到的說法:

java.sql.SQLSyntaxErrorException: Comparisons between 'CLOB (UCS_BASIC)' and 'CHAR (UCS_BASIC)' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1') 
     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.EmbedStatement.execute(Unknown Source) 
     at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source) 
     at ca.sqlpower.sql.jdbcwrapper.StatementDecorator.execute(StatementDecorator.java:109) 
     at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) 
     at ca.sqlpower.swingui.query.SQLQueryUIComponents$DefaultStatementExecutor.executeStatement(SQLQueryUIComponents.java:523) 
     at ca.sqlpower.swingui.query.SQLQueryUIComponents$ExecuteSQLWorker.doStuff(SQLQueryUIComponents.java:437) 
     at ca.sqlpower.swingui.SPSwingWorker.run(SPSwingWorker.java:104) 
     at java.lang.Thread.run(Thread.java:722) 
    Caused by: java.sql.SQLException: Comparisons between 'CLOB (UCS_BASIC)' and 'CHAR (UCS_BASIC)' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1') 
     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) 
     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) 
     ... 14 more 
    Caused by: ERROR 42818: Comparisons between 'CLOB (UCS_BASIC)' and 'CHAR (UCS_BASIC)' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1') 
     at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) 
     at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindComparisonOperator(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) 
     ... 8 more 

爲什麼我用clob代替VARCHAR? 原因我需要無限長度的文本。

如何設置參數?

psmt.setString(1, value); 

然後我嘗試:

psmt.setClob(1, new Clob(null, value)); 

1)什麼我是一個做錯了 起初我這一行設置CLOB的列?

2)什麼其他數據類型可以使用,而不是clob,它不需要設置長度?

回答

2

請嘗試以下

SELECT * FROM APP.Stuff where MyClob LIKE 'sometext'