nutzam/nutz — Issue #106: Oracle下使用出现ora-01780问题
Author: pangwu86
Created: 2011-11-08 18:46:02+00:00
State: open
Labels: Dao

这是个比较特殊的情况

String COMMENT_TABLE = "COMMENT ON TABLE $table IS @tableComment";
Sql tableCommentSQL = Sqls.create(COMMENT_TABLE);
tableCommentSQL.vars().set("table", en.getTableName());
tableCommentSQL.params().set("tableComment", en.getTableComment());

执行后报错

org.nutz.dao.DaoException: org.nutz.dao.DaoException: !Nutz SQL Error: 'COMMENT ON TABLE t_twc IS '测试表''
PreparedStatement:
'COMMENT ON TABLE t_twc IS ?'
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:74)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:178)
at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:169)
at org.nutz.dao.impl.jdbc.oracle.OracleJdbcExpert.addComment(OracleJdbcExpert.java:157)
at org.nutz.dao.impl.jdbc.oracle.OracleJdbcExpert.createEntity(OracleJdbcExpert.java:126)
at org.nutz.dao.impl.NutDao.create(NutDao.java:625)
at org.nutz.dao.test.normal.CreateTableWithCommentTest.createTableInOracle(CreateTableWithCommentTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'COMMENT ON TABLE t_twc IS '测试表''
PreparedStatement:
'COMMENT ON TABLE t_twc IS ?'
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:147)
at org.nutz.dao.impl.DaoSupport$2.invoke(DaoSupport.java:181)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:63)
... 31 more
Caused by: java.sql.SQLException: ORA-01780: 要求文字字符串

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:966)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1170)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3445)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:177)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:139)
... 33 more

应该是使用了PreparedStatement 的问题
Oracle中要求Comment这个比较特殊的玩意儿 ，要求 is 后面必须是用引号括起来的字符串
COMMENT ON TABLE t_twc IS ? 这样这玩意儿就报错了

这个issue只是提出来，可以不修正，毕竟这种情况比较特殊