JDBC串連Oracle資料庫常見問題及解決方案

來源:互聯網
上載者:User
oracle|解決|資料|資料庫|問題
    1. Jbuilder正確串連 oracle 9i需要注意的幾個問題
    2. oracle8以上的應該都使用classes12.jar檔案作為jdbc驅動;
    • 正確設定windows的classpath和jbuilder中的enterprise setup 、configure libraries,將casses12.jar路徑正確添加到上述需要設定的地方;
    • 進入database pilot,在database pilot中,file---new 在driver列表中如果oracle的驅動是紅色的,就說明你的oralce在jb中載入失敗;
    • 若③沒有錯,則建立一個url:jdbc:oracle:thin:@(yourhostname):1521:(your sid)
    • 串連資料庫的Username/password
    1. 注:大部分站友的jbuilder串連oracle的問題都是由於沒有正確配置classpath等引起的。
    2. 使用非XA方式串連ORACLE資料庫

      在windows下配置Oracle_XA時要注意兩點:

      #ORACLE 10
      Oracle_XA;xaosw;%ORACLE_HOME% dbms oraxa10.lib%ORACLE_HOME%precompibmsvcorasql10.lib

      #oracle 9
      Oracle_XA;xaosw;%ORACLE_HOME% dbms oraxa9.lib%ORACLE_HOME%precompibmsvcorasql9.lib

      Unix下
      Oracle_XA:xaosw:....

      第一:在windows 下 ORACLE_XA 和xaosw後面的是分號";",不是冒號":"
      第二:上面的這些LIB寫在一行上,中間用空格分開,如果沒有在系統的環境變數中設定ORACLE_HOME,就寫絕對路徑。

    3. JDBC操作ORACLE資料庫時出現‘java.sql.SQLException:IO異常,不在流模式下’
    4. 用OracleStatment,,不要用java.sql.Statment
    5. 如果對已有串連進行setAutoCommit失敗,則關閉該串連並重建立立一個串連
    6. 到ORACLE網站下載一個最新的JDBC Driver,如果操作LOB類型,用ORACLE內建的介面和類
    7. weblogic串連oracle問題:The Network Adapter could not establish the connection

      可能是伺服器的監聽停掉了,是資料庫的問題,與應用無關;應該先檢查一下oracle是否正常,用sql*plus串連一下資料庫,看能否正常串連;

    8. Weblogic中使用Oracle串連池及Oracle備份的注意事項

      使用HP-UNIX,Weblogic 8.1,Oracle 9.2.0.5
      配置了一個普通的串連池,驅動程式採用oracle的Oracle’s Driver(Thin) version 9.0.1, 9.2.0

      錯誤情況:
      結果使用資料庫連接池時報錯,說沒有串連池資源了。實際上資料庫的串連池完全空閑,並且測試也是對的,Oracle也是正常可以串連、使用的。

      問題根源:
      通過層層排錯,發現原來後台在使用Oracle的exp備份一個只有同義字的使用者,導致exp進程僵死。
      殺死exp、重啟Oracle等無法解決問題,最終重啟UNIX,禁止備份只有同義字的使用者,問題解決。

      總結:
      應該是Oracle9的exp BUG導致串連池問題,不要使用exp倒出同義字

    9. 串連Oracle時拋出如下異常:java.sql.SQLException: Io exception:The Network Adapter could not establish connection一種產生原因

      Oracle Database Connection (from oracle.com)
      PROBLEM
      You are attempting to connect to an Oracle instance using JDBC and you are receiving the following error. 
         java.sql.SQLException: Io exception:
           The Network Adapter could not establish connection
         SQLException: SQLState (null) vendor code (17002)
      Any or all of the following conditions may also apply:
      1) You are able to establish a SQL*Plus connection from the same
         client to the same Oracle instance.
      2) You are able to establish a JDBC OCI connection, but not a Thin
         connection from the same client to the same Oracle instance.
      3) The same JDBC application is able to connect from a different
         client to the same Oracle instance.
      4) The same behavior applies whether the initial JDBC connection
         string specifies a hostname or an IP address.
      REDISCOVERY 
      To verify whether you are hitting this problem, verify whether the Oracle instance is configured for Multithreaded Server (MTS). If the Oracle instance is not configured for MTS, you are probably encountering a different problem. Otherwise, continue. Try forcing the JDBC connection to use a dedicated server instead of a shared server. This can be accomplished in several ways. For JDBC OCI or Thin, this can be done by reconfiguring the server for dedicated connections only. This approach, however, may not be feasible in many cases. In such cases, the following options apply: For JDBC OCI:  
      1) Add the (SERVER=DEDICATED) property to the TNS connect string
         stored in the tnsnames.ora file on the client.
      2) Set the user_dedicated_server=ON in sqlnet.ora on the client.
      For JDBC Thin:
      You must specify a full name-value pair connect string (the same as it might appear in the tnsnames.ora file) instead of the short JDBC Thin syntax. For example, instead of
      "jdbc:oracle:thin::port:sid"
      you would need to use a string of the form
      "jdbc:oracle:thin:@(DESCRIPTION="                    +
                             "(ADDRESS_LIST="              +
                                 "(ADDRESS=(PROTOCOL=TCP)" +
                                          "(HOST=host)"    +                                      =
                                          "(PORT=port)"    +
                                 ")"                       +
                             ")"                           +
                             "(CONNECT_DATA="              +
                                 "(SERVICE_NAME=sid)"      +
                                 "(SERVER=DEDICATED)"      +
                             ")"                           +
                           ")"
      If the connection works fine after having made these changes, it is very likely that this is the problem you are encountering. In this case, one last test will help to verify this fact.
      Log into the remote host on which the Oracle instance is running and execute the appropriate command to determine what the server 'thinks' its hostname is (i.e. the name that was configured when the server was installed and configured). For example, on a Unix host the 'hostname' command can be used for this purpose.
      Using the name displayed (e.g. by the hostname command), exactly as it appeared (i.e. if the output from the hostname command had the domain name included, then include it), return to the client which was unable to connect and try pinging the server.
      NOTE: It is critical that you attempt to ping the server using EXACTLY the same hostname you got from the server.
      If you are unable to ping the server via this hostname, then you almost certainly hitting this problem. If not, this may be a new issue, but at least you will have found a workaround (i.e. use a dedicated connection).
      EXPLANATION 
      To understand why this problem occurs, one must first understand the differences in how the listener handles connections to shared servers versus dedicated servers.
      When connecting to a dedicated server, the client connects to the listener (via hostname or IP address). The listener then spawns a dedicated server process and hands off the socket used to accept the client connection to that server. The client and server then start communicating via the endpoints established by the initial connection. NOTE: There is only one connection in this case. When connecting to a shared server, the initial client connection to the listener is the same. However, with MTS, there is no need to spawn a new server process; a pool of shared processes already exists. Also, clients do not communicate directly with the server processes in MTS; rather, they communicate with a dispatcher.
      For this reason, when setting up an MTS connection, the listener sends a redirect message back to the client asking the client to close the connection to the listener and connect to a dispatcher. The information in this message includes the hostname and a port number for the appropriate dispatcher. The redirect message will ALWAYS specify a hostname, even if the client initially provided an IP address.
      If, for any reason, the hostname provided to the listener (e.g. by the 'hostname' or another command) doesn't agree with the hostname by which the server is known on the client, the connection fails.
      On the other hand, if "(SERVER=DEDICATED)" already appears in the TNS connect string in tnsnames.ora or if "use_dedicated_server=ON" already appears in the sqlnet.ora file, you may find that SQL*Plus and/or JDBC OCI work fine, while JDBC Thin fails.
      SOLUTION 
      Obviously, one solution is to use dedicated servers. However, this may not always be feasible.
      The key is to make sure the hostname on both the client and server agree. This can be accomplished by reconfiguring either the client or the server, but there are things to be aware of in both cases.
      If the server is configured to return a different hostname, then it is possible that other clients which used to work will now fail.
      In some cases, it may not be feasible to reconfigure the client. For example, if the server version of the hostname does not include the domain, you would need to remove the domain portion of the hostname on the client; but, if the client needs to connect to more than one server with the same base name in different domains, this may not be possible, as the hostname may be ambiguous.
      REFERENCES 
      bug:1269734 java.sql.SQLException: Io exception: The Network Adapter could not be found.

    1. 串連ORACLE資料庫報錯:javax.naming.NameNotFoundException: Unable to resolve oracThin. Resolved: '' Unresolved:'oracThin' ; remaining name '' 
    2. 問題描述:配置完JDBC後,開啟頁面的時候,報出如下錯誤資訊:
      javax.naming.NameNotFoundException: Unable to resolve oracThin. Resolved: '' Unresolved:'oracThin' ; remaining name ''
      JDBC配置如下:
      Connection Pools(串連池)
      Name:OracThin
      URL:jdbc:oracle:thin.0.0.1:LYSIMIS
      Driver Classname:oracle.jdbc.driver.OracleDriver
      Properties:
      user=system
      password=manager
      dll=ocijdbc8
      protocol=thin
      資料來源配置如下:
      Name:OracThin
      JNDI Name:OracThin
      Pool Name:OracThin
      當程式執行到這一步時出錯。
      ctx = new InitialContext();
      ds = (javax.sql.DataSource)ctx.lookup ("OracThin"); 
    3. 問題解決後漢字是亂碼 
    4. 錯誤產生原因及解決辦法:
    5. URL:jdbc:oracle:thin:.0.0.1:1521:LYSIMI,thin後面加:,127.0.0.1後面加連接埠號碼
    • 注意名字大小寫.
    • target 到server上
    • 再看看pool是否起來了,沒起來的話,重起weblogic
    • 亂碼問題(Java是基於Unicode):
      • 在JSP 檔案中加入<%@ page contentType="text/html; charset=GBK" %>
      • 在weblogic.xml檔案的<jsp-descriptor>部分加入
        <jsp-descriptor>
        <jsp-param>
        <param-name>compilerSupportsEncoding</param-name>
        <param-value>true</param-value>
        </jsp-param>
        <jsp-param>
        <param-name>encoding</param-name>
        <param-value>GBK</param-value>
        </jsp-param>
        </jsp-descriptor>
    1. oracle XA的疑惑

      問題描述:Oracle_XA;xaosw;D:oracleora92 dbmsXAORAXA9.lib C:msvcoraSQL9.lib中
      xaosw是什麼意思

      解答:可以參考ORACLE的XA部分的文檔。

      http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch_xa.htm

    2. oracle與weblogic自動啟動與停止

      問題描述:每次重新啟動伺服器時oracle資料庫若沒有關閉,則必須先關閉後在重新啟動redhat advance server,oracle才能夠正常運行

      原因及解決辦法參見:

      http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=81&threadID=8839&messageID=43184



    相關文章

    Beyond APAC's No.1 Cloud

    19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

    Learn more >

    Apsara Conference 2019

    The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

    Learn more >

    Alibaba Cloud Free Trial

    Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

    Learn more >

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。