• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Weblogic6.0上Connection Pool、DataSource的创建与使用

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网 2002年1月16日
                                                                  整理人:wangyl
注意
l    以下文档都是以mydomain为例
l    本系列文档都是使用相同的配置,即使用以前文档的配置,

1.    将附件中的classes12.zip拷贝到wlserver6.0\lib目录下
2.    修改config\mydomain\startWebLogic.cmd文件,在set CLASSPATH=。。。一行的最后加入如下语句
;.\lib\classes12.zip
3.  修改mydomain\config.xml文件,在最后加入如下语句
<JDBCConnectionPool
      CapacityIncrement="1"
      DriverName="oracle.jdbc.driver.OracleDriver"
      InitialCapacity="2"
      MaxCapacity="4"
      Name="OracleThinPool"
      Properties="user=zjcenter;password=zjcenter;dll=ocijdbc8;protocol=thin"
      Targets="myserver"
      URL="jdbc:oracle:thin:@172.16.91.36:1521:ORCL"//此处根据你的服务器地址做调整//
  />

<JDBCTxDataSource
      JNDIName="WebApp.OracleThintxds"
      Name="otxds"
      PoolName="OracleThinPool"
      Targets="myserver"
/>

4.    将附件中的sss.class拷贝到mydomain\applications\WebApp\WEB-INF\classes目录下

5.    修改mydomain\applications\WebApp\WEB-INF\web.xml文件,在
   <web-app>
。。。。。。
。。。。。。
</web-app>
之间加入如下语句

<servlet>
    <servlet-name>DataSourceTest</servlet-name>
    <servlet-class>sss</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>DataSourceTest</servlet-name>
    <url-pattern>/dst/*</url-pattern>
</servlet-mapping>

6.    启动Weblogic Default Server
7.    访问我们的例子http://127.0.0.1:7001/WebApp/dst
8.    测试成功!
9.    例子sss.java
// Source File Name:   sss.java

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletResponse;
import javax.servlet.http.*;
import javax.sql.DataSource;

public class sss extends HttpServlet
{

    public sss()
    {
    }

    public void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws IOException
    {
        httpservletresponse.setContentType("text/html");
        PrintWriter printwriter = httpservletresponse.getWriter();
        printwriter.println("<html><head><title>Hello datasource!</title></head><body>");
        printwriter.println("<p><img src=images/BEA_Button_Final_web.gif align=right>");
        printwriter.println("<H1>simplesqlServlet.java</h1> Attempting connection....");
        Connection connection = null;
        Statement statement = null;
        try
        {
            InitialContext initialcontext = new InitialContext();
            DataSource datasource = (DataSource)initialcontext.lookup("bbb.OracleThintxds");
            connection = datasource.getConnection();
            printwriter.println("<p>Connection successful...<p>Executing SQL...<p>");
            statement = connection.createStatement();
            try
            {
                statement.execute("drop table empdemo");
                printwriter.println("Table empdemo dropped...<p>");
            }
            catch(SQLException sqlexception)
            {
                printwriter.println("<p>Table empdemo does not need to be dropped...<p>");
            }
            statement.execute("create table empdemo (empid int, name varchar(30), dept int)");
            printwriter.println("<p>Table empdemo created...");
            int i = statement.executeUpdate("insert into empdemo values (0,@#John Smith@#, 12)");
            printwriter.println("<p>Number of rows inserted = " + i);
            statement.execute("select * from empdemo");
            ResultSet resultset = statement.getResultSet();
            printwriter.println("<hr>Querying data ...<br>");
            for(; resultset.next(); printwriter.println("<br><b>ID:  </b> " + resultset.getString("empid") + "<br><b>Name:</b> " + resultset.getString("name") + "<br><b>Dept:</b> " + resultset.getString("dept") + "<hr>"));
            ResultSetMetaData resultsetmetadata = resultset.getMetaData();
            printwriter.println("Querying table meta data...<p>");
            printwriter.println("Number of Columns: " + resultsetmetadata.getColumnCount() + "<b>");
            for(int j = 1; j <= resultsetmetadata.getColumnCount(); j++)
            {
                printwriter.println("<p>Column Name: " + resultsetmetadata.getColumnName(j));
                printwriter.println("<br>Nullable: " + resultsetmetadata.isNullable(j));
                printwriter.println("<br>Precision: " + resultsetmetadata.getPrecision(j));
                printwriter.println("<br>Scale: " + resultsetmetadata.getScale(j));
                printwriter.println("<br>Size: " + resultsetmetadata.getColumnDisplaySize(j));
                printwriter.println("<br>Column Type: " + resultsetmetadata.getColumnType(j));
                printwriter.println("<br>Column Type Name: " + resultsetmetadata.getColumnTypeName(j));
                printwriter.println("<br><hr>");
            }

        }
        catch(Exception exception)
        {
            printwriter.println("Connection error:" + exception);
        }
        finally
        {
            try
            {
                if(connection != null)
                    connection.close();
                printwriter.println("********************************");
                printwriter.println("\n");
                printwriter.println("stmt is");
                printwriter.println(statement);
                printwriter.println("\n");
                printwriter.println("conn is");
                printwriter.println(connection);
                printwriter.println("********************************");
                if(statement != null)
                    statement.close();
            }
            catch(SQLException sqlexception1)
            {
                printwriter.println("Exception during close()" + sqlexception1.getMessage());
            }
        }
        printwriter.println("</b><h3>Example finished...</h3></body></html>");
    }
}

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网