glassfish连接池的配置

最近因为要在glassfish上使用mssql2005的数据库,总是配置不得法,还好,找到一个示例,终于成功了,帖出来,有能用得上的来看看吧。

 

文章的原出处:http://philip01.javaeye.com/blog/259288

 

lassFish MySql连接池配置

第一步:复制D:/glassfish/lib/install/templates/resources/jdbc/mysql_type4_datasource.xml

  到D:/glassfish/domains/s317/config

  [注:s317是 domain名称] , 并命名为msql.xml

 

 

第二步:编缉D:/glassfish/domains/s317/config/msql.xml

<?xml version="1.0" encoding="UTF-8"?>

<resources>

  <jdbc-connection-pool 

  name="mysql_pool" 

  datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"

  res-type="javax.sql.DataSource">

  <property name="user" value="root"/>

  <property name="password" value="root"/>

  <property name="url" value="jdbc:mysql://localhost:3306/s317"/>

  </jdbc-connection-pool>

 

  <jdbc-resource 

  enabled="true" 

  jndi-name="jdbc/MySqlDB" 

  object-type="user" 

  pool-name=" mysql_pool "/>

</resources>

第三步:复制mysql-connector-java-3.1.10-bin.jar到

  D:/glassfish/domains/s317/lib/ext 目录下

 

第四步:D:/glassfish/bin>asadmin start-domain s317 

 

第五步:asadmin add-resources msyql.xml

第六步:asadmin ping-connection-pool mysql_pool

第七步:向web.xml加入下面的内容 

  <resource-ref>

  <description>DBPool Connection</description>

  <res-ref-name>jdbc/MySqlDB</res-ref-name>

  <res-type>javax.sql.DataSource</res-type>

  <res-auth>Container</res-auth>

  </resource-ref>

 

第八步:编写测试页面jdbc.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

  pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="javax.naming.Context"%>

<%@page import="javax.naming.InitialContext"%>

<%@page import="javax.sql.DataSource"%>

<%@page import="java.sql.Connection"%>

<%@page import="java.sql.ResultSet"%>

<%@page import="java.sql.Statement"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<%

ResultSet rs = null;

Statement stmt = null;

Connection conn = null;

try{

  String strJNDIName = "jdbc/MySqlDB";

  Context initialcontext = null;

  initialcontext = new InitialContext();

  DataSource datasource = (DataSource) initialcontext.lookup(strJNDIName);

  conn = datasource.getConnection();

  stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

   

  rs = stmt.executeQuery("select * from jbpm_task");

   

  while(rs.next()){

   

  out.println(rs.getString("ID_"));

  }

}

catch(Exception e){

  System.out.println(e.toString());

}finally{

  if(rs != null){

  rs.close();

  rs = null;

  }

  if(stmt != null){

  stmt.close();

  stmt = null;

  }

}

%> 

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值