Java項目,從Oracle遷移到達夢資料庫筆記

來源:互聯網
上載者:User

達夢資料庫是個國產資料庫,據說對Oracle有很好的相容,本人親自從Oracle11g遷移到達夢6.0的資料庫上來,遇到一些問題,以下是問題記錄:

1。欄位名錯誤
雖然達夢SQL可以相容欄位大小寫,但是JDVC實際上執行與Oracle會有差別,

達夢的SQL可以執行,但是返回的欄位的列名仍然按SQL的大小寫返回,而Oracle會變成全部的大寫返回,

select typeid, typename from T_PUB_PRODUCT_TYPE

在用oracle執行後返回的列名叫TYPEID,TYPENAME

達夢傳回值則為typeid,typename

比較好的做法是在資料庫執行語句之前,強制所有語句轉大寫:

rs = stmt.executeQuery(strSql.toUpperCase());    //達夢資料庫對列名區分大小寫,Oracle會自動全轉大寫

==============================================
cuont(*)資料類型錯誤
語句:
select count(*) counts  from t_cus_product left join t_pub_product_type on p_type=typeid where p_createrid=200

oracle的count(*)可以相容BigDecimal,達夢的count(*)是Long型
        //count = ((BigDecimal)mapCount.get("counts")).intValue();//Orcale 為 BigDecimal
        count = ((Long)mapCount.get("counts")).intValue();   //達夢資料庫為Long


=====================================================
2。達夢資料庫文法關鍵字錯誤

以下語句oracle 可以執行,達夢卻報錯誤
select c.contractid,CONTRACTNO, c.contractname, c.type, sum,begin,end
state, userid, serviceid,P_NAME
from t_contract c
left join T_CUS_PRODUCT
 on c.PRODUCTID=P_ID
  where userid=200 order by contractid
 
原因:begin,end為達夢的保留關鍵字,語句修改為雙引號的形式,可以通過:
select c.contractid,CONTRACTNO, c.contractname, c.type, sum,"begin","end"
state, userid, serviceid,P_NAME
from t_contract c
left join T_CUS_PRODUCT
 on c.PRODUCTID=P_ID
   where userid=200 order by contractid
=============================================
3。查詢dual表報錯,
語句:select seq_c006_message_content.nextval from dual

java報錯:
java.sql.SQLException: 無效的表或視圖名 'dual'
    at dm.jdbc.dbaccess.DBError.throwSQLException(Unknown Source)
    at dm.jdbc.driver.DmdbCSI.prepareSQL(Unknown Source)
    at dm.jdbc.driver.DmdbStatement.directExec(Unknown Source)
    at dm.jdbc.driver.DmdbStatement.executeQuery(Unknown Source)
    at cn.org.hz.common.dao.DBAccess.queryOneRow(DBAccess.java:110)
    at cn.org.hz.blh.i007.I007Blh.I007MessageAdd(I007Blh.java:136)
    at cn.org.hz.blh.i007.I007Blh$$FastClassByCGLIB$$f90d5dcf.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at cn.org.hz.common.aop.AroundInterceptor.invoke(AroundInterceptor.java:13)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    at cn.org.hz.blh.i007.I007Blh$$EnhancerByCGLIB$$67fbf5f5.I007MessageAdd(<generated>)
    at cn.org.hz.ctrl.i007.I007Ctrl.I007MessageAdd(I007Ctrl.java:113)
    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.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at cn.org.hz.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:23)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619)

解決在本使用者下建立一個dual同義字
如果需要直接存取,可以用SYSDBA建立一個PUBLIC同義字:
CREATE PUBLIC SYNONYM dual for SYSTEM.SYSDBA.SYSDUAL;

達夢雖然在sysdba下造了一個dual表來相容oracle但是卻沒有在每個新使用者下建立同義字,所有一般對dual表的查詢都會報錯。

=================================================

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.