久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='0z49L'></small><noframes id='0z49L'>

      <bdo id='0z49L'></bdo><ul id='0z49L'></ul>

      <tfoot id='0z49L'></tfoot>

      <i id='0z49L'><tr id='0z49L'><dt id='0z49L'><q id='0z49L'><span id='0z49L'><b id='0z49L'><form id='0z49L'><ins id='0z49L'></ins><ul id='0z49L'></ul><sub id='0z49L'></sub></form><legend id='0z49L'></legend><bdo id='0z49L'><pre id='0z49L'><center id='0z49L'></center></pre></bdo></b><th id='0z49L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0z49L'><tfoot id='0z49L'></tfoot><dl id='0z49L'><fieldset id='0z49L'></fieldset></dl></div>
      <legend id='0z49L'><style id='0z49L'><dir id='0z49L'><q id='0z49L'></q></dir></style></legend>

    1. 如何使用給定的 JNDI 名稱連接到 Websphere 數據源

      How do I connect to a Websphere Datasource with a given JNDI name?(如何使用給定的 JNDI 名稱連接到 Websphere 數據源?)

          <bdo id='NOCHw'></bdo><ul id='NOCHw'></ul>
        • <tfoot id='NOCHw'></tfoot>
          <i id='NOCHw'><tr id='NOCHw'><dt id='NOCHw'><q id='NOCHw'><span id='NOCHw'><b id='NOCHw'><form id='NOCHw'><ins id='NOCHw'></ins><ul id='NOCHw'></ul><sub id='NOCHw'></sub></form><legend id='NOCHw'></legend><bdo id='NOCHw'><pre id='NOCHw'><center id='NOCHw'></center></pre></bdo></b><th id='NOCHw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NOCHw'><tfoot id='NOCHw'></tfoot><dl id='NOCHw'><fieldset id='NOCHw'></fieldset></dl></div>

            <small id='NOCHw'></small><noframes id='NOCHw'>

            <legend id='NOCHw'><style id='NOCHw'><dir id='NOCHw'><q id='NOCHw'></q></dir></style></legend>
                <tbody id='NOCHw'></tbody>
              • 本文介紹了如何使用給定的 JNDI 名稱連接到 Websphere 數據源?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 Websphere Portal 7.0 并使用 RAD 8.0 創建一個 portlet.我的 portlet 正在嘗試與遠程服務器建立 db2 連接.我在本地編寫了一個 java 程序來與服務器建立基本的 JDBC 連接并從表中獲取記錄.代碼工作正常;但是,當我將代碼添加到我的 portlet 以及 db2jcc4.jar 時,連接不起作用.我正在使用基本的:

                I'm using Websphere Portal 7.0 and creating a portlet with RAD 8.0. My portlet is trying to make a db2 connection to a remote server. I wrote a java program locally to do a basic JDBC connection to the server and get records from a table. The code works fine; however, when I add the code to my portlet as well as the db2jcc4.jar, the connection doesn't work. I'm using the basic:

                Connection connection = DriverManager.getConnection("jdbc:db2://server:port/db:user=user;password=pw;");
                

                我認為使用 Websphere 數據源是正確的方法.我知道數據源的 JNDI 名稱,但我沒有找到關于如何建立連接的明確示例.幾個例子使用了一個 DataSource 類(我輸入了這個,這似乎不是來自本地 java 包,所以我在這里使用什么導入?)加上一個 Context.我遇到過這樣的代碼:

                I figure that using the Websphere datasource is the right way to go. I know the JNDI name for the datasource, but I'm not finding clear cut examples on how to make a connection. Several examples use a DataSource class (I typed this in and this doesn't seem like it comes from a native java package so what import do I use here?) coupled with a Context. I've come across code like:

                Context ctx = new InitialContext();
                ctx.lookup("jdbc/xxxx");
                

                ...有人可以幫我分解一下嗎?

                ... Can someone break this down for me?

                編輯 1

                我已根據列出的答案更新了我的代碼.我真的覺得我越來越近了.這是我的 getConnection() 方法:

                I've updated my code per the answers listed. I really think I'm getting closer. Here is my getConnection() method:

                private Connection getConnection() throws SQLException {
                    javax.naming.InitialContext ctx = null;
                    javax.sql.DataSource ds = null;
                    System.out.println("Attempting connection..." + DateUtil.now() );
                    try {
                        ctx = new javax.naming.InitialContext();
                        ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/db");
                        connection = ds.getConnection();
                    } catch (NamingException e) {
                        System.out.println("peformanceappraisalstatus: COULDN'T CREATE CONNECTION!");
                        e.printStackTrace();
                    }       
                    System.out.println("connection: " + connection.getClass().getName() + " at " + DateUtil.now());
                    return connection;
                }
                

                我的整個 web.xml 文件看起來像:

                My entire web.xml file looks like:

                <?xml version="1.0" encoding="UTF-8"?>
                <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                    <display-name>PeformanceAppraisalStatus</display-name>
                    <welcome-file-list>
                        <welcome-file>index.html</welcome-file>
                        <welcome-file>index.htm</welcome-file>
                        <welcome-file>index.jsp</welcome-file>
                        <welcome-file>default.html</welcome-file>
                        <welcome-file>default.htm</welcome-file>
                        <welcome-file>default.jsp</welcome-file>
                    </welcome-file-list>
                    <resource-ref>
                        <description>
                        Datasource connection to Db</description>
                        <res-ref-name>jdbc/db</res-ref-name>
                        <res-type>javax.sql.DataSource</res-type>
                        <res-auth>Container</res-auth>
                        <res-sharing-scope>Shareable</res-sharing-scope>
                    </resource-ref>
                </web-app>
                

                我看到一個錯誤,描述了你們告訴我的 Websphere 應該提示我做的事情,但沒有:

                I am seeing an error that describes the very thing you guys are telling me Websphere should prompt me to do, but doesn't:

                SRVE0169I: Loading Web Module: PeformanceAppraisalStatus.
                [8/23/11 18:08:02:166 CDT] 00000009 InjectionProc E   CWNEN0044E: A resource reference binding could not be found for the jdbc/db resource reference, defined for the PeformanceAppraisalStatus component.
                [8/23/11 18:08:02:169 CDT] 00000009 InjectionEngi E   CWNEN0011E:  The injection engine failed to process bindings for the metadata.
                

                是的,我知道我在整個應用程序中將性能拼寫為性能.

                Yes, I know that I've mispelled performance as peformance throughout the app.

                解決方案

                我是如此接近.以下是使其全部到位的缺失部分:

                I was so very close. Here are the missing bits that made it all fall into place:

                web.xml:
                <resource-ref>      
                    <description>
                    Datasource connection to db</description>
                    <res-ref-name>jdbc/db</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
                    <res-sharing-scope>Shareable</res-sharing-scope>
                    <mapped-name>jdbc/db</mapped-name>      
                </resource-ref>
                
                ibm-web-bnd.xml:
                <?xml version="1.0" encoding="UTF-8"?>
                <web-bnd 
                    xmlns="http://websphere.ibm.com/xml/ns/javaee"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
                    version="1.0">
                
                    <virtual-host name="default_host" />
                
                
                    <resource-ref name="jdbc/db" binding-name="jdbc/mydatasource" />
                </web-bnd>
                

                似乎 ibm-web-bnd.xml 文件處理了項目資源名稱和 websphere 中的數據源之間的綁定.一旦我添加了這一行:

                It appears that the ibm-web-bnd.xml file handles the binding between the project resource name and the datasource in websphere. Once I added the line:

                <resource-ref name="jdbc/db" binding-name="jdbc/mydatasource" />
                

                Websphere Portal 似乎得到了安撫.我的代碼現在正在工作并連接到數據庫.

                Websphere Portal seemed appeased. My code is working and connecting to the database now.

                推薦答案

                您需要在您的應用程序中定義一個資源引用,然后在執行期間將該邏輯資源引用映射到物理資源(數據源)部署.

                You need to define a resource reference in your application and then map that logical resource reference to the physical resource (data source) during deployment.

                在您的 web.xml 中,添加以下配置(根據需要修改名稱和屬性):

                In your web.xml, add the following configuration (modifying the names and properties as appropriate):

                <resource-ref>
                    <description>Resource reference to my database</description>
                    <res-ref-name>jdbc/MyDB</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <res-auth>Container</res-auth>
                    <res-sharing-scope>Shareable</res-sharing-scope>
                </resource-ref>
                

                然后,在應用程序部署期間,WAS 會提示您將此資源引用(jdbc/MyDB)映射到您在 WAS 中創建的數據源.

                Then, during application deployment, WAS will prompt you to map this resource reference (jdbc/MyDB) to the data source you created in WAS.

                在您的代碼中,您可以獲得與您在示例中顯示的方式類似的 DataSource;但是,用于查找的 JNDI 名稱實際上應該是您定義的資源引用的名稱 (res-ref-name),而不是物理數據源的 JNDI 名稱.此外,您需要在 res-ref-name 前面加上應用程序命名上下文 (java:comp/env/).

                In your code, you can obtain the DataSource similar to how you've shown it in your example; however, the JNDI name you'll use to look it up should actually be the resource reference's name you defined (res-ref-name), rather than the JNDI name of the physical data source. Also, you'll need to prefix the res-ref-name with the application naming context (java:comp/env/).

                Context ctx = new InitialContext();
                DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/MyDB");
                

                這篇關于如何使用給定的 JNDI 名稱連接到 Websphere 數據源?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  <tbody id='RFhdI'></tbody>

                      <i id='RFhdI'><tr id='RFhdI'><dt id='RFhdI'><q id='RFhdI'><span id='RFhdI'><b id='RFhdI'><form id='RFhdI'><ins id='RFhdI'></ins><ul id='RFhdI'></ul><sub id='RFhdI'></sub></form><legend id='RFhdI'></legend><bdo id='RFhdI'><pre id='RFhdI'><center id='RFhdI'></center></pre></bdo></b><th id='RFhdI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RFhdI'><tfoot id='RFhdI'></tfoot><dl id='RFhdI'><fieldset id='RFhdI'></fieldset></dl></div>
                      • <bdo id='RFhdI'></bdo><ul id='RFhdI'></ul>
                      • <tfoot id='RFhdI'></tfoot>

                          <small id='RFhdI'></small><noframes id='RFhdI'>

                          <legend id='RFhdI'><style id='RFhdI'><dir id='RFhdI'><q id='RFhdI'></q></dir></style></legend>

                          主站蜘蛛池模板: 中文字幕av在线播放 | 久久久久亚洲视频 | 日本一区二区三区精品视频 | 少妇午夜一级艳片欧美精品 | 天天操伊人 | 亚洲成人在线免费 | 久久精品99 | 91电影在线| 97日韩精品 | 国产福利在线看 | 日韩精品一区中文字幕 | 亚洲www| 日韩欧美在 | 天堂精品视频 | 一级特黄在线 | 亚洲视频在线看 | 91.xxx.高清在线 | 亚洲国产精品成人综合久久久 | 精品视频免费 | 青青草av网站 | 人干人人| 欧美精品网 | 超碰国产在线 | av影音| 精品在线99 | 国产成人精品午夜视频免费 | 久久精品一区二区三区四区 | 欧美一a一片一级一片 | 日韩理论电影在线观看 | 亚洲一区二区电影在线观看 | 久久久久久av | 国产精品一级在线观看 | 欧美一区二区三区四区五区无卡码 | 九九99九九精彩46 | 三级欧美 | 日韩中文字幕视频 | 国产伦精品一区二区三区四区视频 | 亚洲人成人一区二区在线观看 | 国产精品久久久久久久久污网站 | 日本亚洲欧美 | 国产精品久久久久久久7电影 |