- 浏览: 739979 次
- 性别:
- 来自: 重庆
文章分类
- 全部博客 (194)
- Webservice (6)
- ExtJs (2)
- Work Summary (4)
- CoreJava (51)
- Spring (10)
- EJB (5)
- struts1.x (3)
- C/C++ (5)
- DatabaseManager (19)
- Hibernate (5)
- Crytology (1)
- Web Server (5)
- Software Manager (5)
- WebUi (39)
- Web page (2)
- android (5)
- struts2 (12)
- Java 导出 Excel (1)
- Spring 与struts2 和Hibernate 4.0注解解决方安 (1)
- Dwr (1)
- maven3 (4)
- Windows (3)
- 表格头部信息不动使用Jquery 外部框架 (1)
- 软件行业动态 (1)
- mybatis (1)
- C# (3)
- MySQL (4)
最新评论
-
July01:
最近了解到一款StratoIO打印控件,功能如下:1、Html ...
LODOP插件开发 -
an52036:
u010980147 写道您的代码确实能生成条形码,但是打印出 ...
Java 条形码生成(一维条形码) -
di1984HIT:
学习了,很好~~
Ant 打包war 生成文件内容build.xml -
lhb319lhb:
如果 ajax(jquery)更新了 iframe 的 src ...
jquery 修改iframe src -
calosteward:
感谢楼主,除了一维条码,有没有相关二维码的资源呢?______ ...
Java 条形码生成(一维条形码)
1. 调用ConnectionPool 使用jndi 查找
在这个目录下有模板
glassfish-3.1.1\lib\install\templates\resources\jdbc
2. 这里我们以DB2和MySQL数据库为例
<?xml version="1.0" encoding="UTF-8"?> <!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. The contents of this file are subject to the terms of either the GNU General Public License Version 2 only ("GPL") or the Common Development and Distribution License("CDDL") (collectively, the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html or packager/legal/LICENSE.txt. See the License for the specific language governing permissions and limitations under the License. When distributing the software, include this License Header Notice in each file and include the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: Oracle designates this particular file as subject to the "Classpath" exception as provided by Oracle in the GPL Version 2 section of the License file that accompanied this code. Modifications: If applicable, add the following below the License Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyright [year] [name of copyright owner]" Contributor(s): If you wish your version of this file to be governed by only the CDDL or only the GPL Version 2, indicate your decision by adding "[Contributor] elects to include this software in this distribution under the [CDDL or GPL Version 2] license." If you don't indicate a single choice of license, a recipient has the option to distribute your version of this file under either the CDDL, the GPL Version 2 or to extend the choice of license to its licensees as provided above. However, if you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the option applies only if the new code is made subject to such option by the copyright holder. --> <!DOCTYPE resources PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 9.0 Domain//EN" "*<install directory>/lib/dtds/sun-resources_1_3.dtd*"> <!-- Sun bundled DataDirect driver for Oracle Databases. (Available in SJSAS EE builds) JAR files for the driver are smdb2.jar, smbase.jar, smutil.jar To learn more on JDBC resources, pl. refer to JDBC resources chapter of admin guide. Administration Guide >> JDBC Resources >> Configurations for Specific JDBC Drivers http://docs.sun.com/app/docs/doc/819-3658/6n5s5nklk?a=view For detailed explanation of attributes and elements of this resources xml pl. refer to sun-resources_1_3.dtd --> <resources> <jdbc-connection-pool name="db2_dd_pool" datasource-classname="com.sun.sql.jdbcx.db2.DB2DataSource" res-type="javax.sql.DataSource"> <property name="user" value="DB_USER"/> <property name="password" value="DB_PASSWORD"/> <property name="serverName" value="DB_HOSTNAME"/> <property name="url" value="jdbc:sun:db2://DB_HOSTNAME:50000;databaseName=DATABASE_NAME"/> <property name="portNumber" value="50000"/> <property name="databaseName" value="DATABASE_NAME"/> </jdbc-connection-pool> <jdbc-resource enabled="true" jndi-name="jdbc/db2_dd_resource" object-type="user" pool-name="db2_dd_pool"/> </resources>
MySql 连接池
<?xml version="1.0" encoding="UTF-8"?> <!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. The contents of this file are subject to the terms of either the GNU General Public License Version 2 only ("GPL") or the Common Development and Distribution License("CDDL") (collectively, the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html or packager/legal/LICENSE.txt. See the License for the specific language governing permissions and limitations under the License. When distributing the software, include this License Header Notice in each file and include the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: Oracle designates this particular file as subject to the "Classpath" exception as provided by Oracle in the GPL Version 2 section of the License file that accompanied this code. Modifications: If applicable, add the following below the License Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyright [year] [name of copyright owner]" Contributor(s): If you wish your version of this file to be governed by only the CDDL or only the GPL Version 2, indicate your decision by adding "[Contributor] elects to include this software in this distribution under the [CDDL or GPL Version 2] license." If you don't indicate a single choice of license, a recipient has the option to distribute your version of this file under either the CDDL, the GPL Version 2 or to extend the choice of license to its licensees as provided above. However, if you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the option applies only if the new code is made subject to such option by the copyright holder. --> <!DOCTYPE resources PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 9.0 Domain//EN" "*<install directory>/lib/dtds/sun-resources_1_3.dtd*"> <!-- MySQL Type 4 Driver The JAR file for the MySQL driver is mysql-connector-java-version-bin-g.jar, for example, mysql-connector-java-5.0.5-bin.jar. To learn more on JDBC resources, pl. refer to JDBC resources chapter of admin guide. Administration Guide >> JDBC Resources >> Configurations for Specific JDBC Drivers http://docs.sun.com/app/docs/doc/819-3658/6n5s5nklk?a=view For detailed explanation of attributes and elements of this resources xml pl. refer to sun-resources_1_3.dtd ====================================================================================================== | res-type datasource-classname | ====================================================================================================== | javax.sql.DataSource com.mysql.jdbc.jdbc2.optional.MysqlDataSource | | javax.sql.ConnectionPoolDataSource com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource | | javax.sql.XADataSource com.mysql.jdbc.jdbc2.optional.MysqlXADataSource | ====================================================================================================== --> <resources> <jdbc-connection-pool name="mysql5-pool" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource"> <property name="user" value="root"/> <property name="password" value="123456"/> <property name="url" value="jdbc:mysql://localhost:3306/itmanager"/> </jdbc-connection-pool> <jdbc-resource enabled="true" jndi-name="jdbc/mysql52" object-type="user" pool-name="mysql5-pool"/> </resources>
3. 在GlassFish 工作域中注册配置信息domain.xml
glassfish-3.1.1\domains\domain1\config
<resources> <jdbc-resource pool-name="mysql5-pool" jndi-name="jdbc/mysql52"></jdbc-resource> <jdbc-resource pool-name="SamplePool" jndi-name="jdbc/sample"></jdbc-resource> <jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin"></jdbc-resource> <jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default"></jdbc-resource> <jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource" name="mysql5-pool"> <property name="user" value="root"></property> <property name="password" value="123456"></property> <property name="url" value="jdbc:mysql://localhost:3306/itmanager"></property> </jdbc-connection-pool> <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource" name="__TimerPool"> <property name="databaseName" value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer"></property> <property name="connectionAttributes" value=";create=true"></property> </jdbc-connection-pool> <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientDataSource" is-isolation-level-guaranteed="false" res-type="javax.sql.DataSource" name="DerbyPool"> <property name="PortNumber" value="1527"></property> <property name="Password" value="APP"></property> <property name="User" value="APP"></property> <property name="serverName" value="localhost"></property> <property name="DatabaseName" value="sun-appserv-samples"></property> <property name="connectionAttributes" value=";create=true"></property> </jdbc-connection-pool> <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource" name="SamplePool"> <property name="DatabaseName" value="sample"></property> <property name="User" value="app"></property> <property name="Password" value="app"></property> <property name="URL" value="jdbc:derby://localhost:1527/sample"></property> <property name="PortNumber" value="1527"></property> <property name="serverName" value="localhost"></property> </jdbc-connection-pool> <jdbc-resource pool-name="mysql5-pool" description="" jndi-name="mysql5"></jdbc-resource> <jdbc-connection-pool driver-classname="" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource" description="" name="uml"> <property name="user" value="root"></property> <property name="password" value="123456"></property> <property name="url" value="jdbc:mysql://localhost:3306/itmanager"></property> </jdbc-connection-pool> <jdbc-resource pool-name="uml" description="" jndi-name="qqq"></jdbc-resource> </resources>
启动glassfish 服务器OK
使用Context API查找DataSource
public static DataSource getDataSource() throws NamingException { Context context = new InitialContext(); return (DataSource)context.lookup("mysql5"); }
就可以查找到数据源了。。其它Jboss 和websphere 都是类型的。。
因为本人对Jboss 很熟悉。。所以这个希望对大家有所帮助
发表评论
-
xdoclet-1.2.3插件的使用
2010-09-14 10:16 2762/** * */ package com.zte. ... -
EJB 3 + Spring 3.x + Struts 2.x + JPA +DWR + MySql 5.0 整合开发,服务器JBoss + Tomcat
2010-08-24 14:10 24381.原理介绍 本架构才用的是Tomcat + Jboss ... -
JBoss和Tomcat 整合
2010-08-20 17:36 5492JBoss 和Tomcat 整合 1.原理介绍 ... -
EJB 3 学习例子 HelloWorld 小程序(使用JNDI)
2010-07-18 15:38 1801用这么久的EJB 3 .0 过去一直用EJB1.x 和 EJB ...
相关推荐
2. 配置连接池 在管理控制台中,选择“连接池”>“新建”,然后按照提示进行配置,包括指定数据库连接的属性,如数据库类型、主机名、端口号、用户名和密码等。 3. 配置 JDBC 数据源 在配置连接池后,需要配置一...
下面,我们将介绍如何在 GlassFish 管理员界面中配置连接池,特别是使用 Oracle 数据库为例。 连接池的概念 ------------- 连接池是一种提高应用程序性能和可靠性的技术,它可以将多个数据库连接组合成一个池,...
要配置连接池,需要遵循以下步骤: 1. 创建连接池 2. 配置连接池参数 3. 测试连接池 四、JNDI 配置 JNDI(Java Naming and Directory Interface)是 Java EE 中的一个命名和目录接口,用于查找和访问 Java EE 组件...
在配置连接池时,不同的连接池实现(如Apache DBCP、C3P0、HikariCP、Tomcat JDBC Pool等)会有各自的属性和配置方式。例如,HikariCP以其高性能而著称,其配置项包括`maximumPoolSize`、`idleTimeout`、`connection...
**Step6:** 配置连接池参数,如最大连接数、最小连接数、超时时间等,以满足你的应用需求。 **Step7:** 完成数据源配置后,需要创建一个JNDI别名,使得应用可以通过JNDI查找这个数据源。回到“JDBC Resources”...
3. **配置连接池参数**:填写相关配置信息,包括数据库URL、用户名、密码、最小和最大连接数等,然后保存设置。 4. **创建JDBC Resources (JNDI)**:定义一个JNDI名称,与之前创建的连接池关联,这样应用可以通过...
- 使用连接池来优化数据库连接管理,如C3P0、HikariCP或Apache DBCP,它们能有效管理和复用数据库连接,减少资源消耗。 - 定期检查和更新数据源配置,以适应数据库的升级或安全策略变更。 - 在生产环境中,确保...
在 GlassFish 中,需要配置 JDBC 连接池。配置完成后,需要创建受管节点和实例。创建受管节点可以使用以下命令:`./asadmin create-instance --host h3cpdm20-ts --port 4848 -nodeagent h3cpdm20-tsNode`。创建完成...
7. **性能优化**:内置了JVM调优工具,可以分析和优化服务器性能,同时支持连接池和缓存管理,以提高响应速度。 8. **社区支持**:GlassFish拥有活跃的开发者社区,不断推动其发展和更新,提供各种插件、教程和问题...
- **连接池配置:** 调整数据库连接池的最大连接数、空闲时间等参数。 - **缓存机制:** 实现应用层面的缓存机制来减少数据库访问频率。 **2. 高可用性与集群:** - **集群部署:** 通过集群实现负载均衡和故障...
2. **域管理**:GlassFish使用域的概念来组织多个服务器实例,域配置包括了服务器设置、数据源、连接池、安全管理器等。文档会详细介绍如何创建、配置和管理这些域。 3. **命令行工具**:GlassFish提供了一套强大的...
在Glassfish管理控制台的“Resources”->“JDBC”部分,你可以创建JDBC资源和连接池。这通常涉及设置数据源名称、JDBC驱动类、URL、用户名和密码等属性。配置完成后,应用程序可以通过JNDI查找来访问这些数据源。 ...
内容可能包括内存配置、线程池调整、数据库连接池优化、日志和监控等方面。性能调优是确保应用高效运行的关键,它涉及到资源分配、并发控制、缓存策略等多个方面。 5. **使用手册** Glassfish API的使用手册是...
例如,你可以通过管理控制台创建和管理数据源、连接池、邮件会话,以及监控应用程序性能。 - 数据源配置:为应用程序提供数据库连接,通过管理控制台可以添加、删除和配置JDBC数据源。 - 集群部署:在多个GlassFish...
在GlassFish中配置数据源,需要在管理控制台创建JDBC资源和连接池,指定数据库驱动、URL、用户名和密码等信息,以使应用能够连接到数据库。 六、GlassFish 设置及其安装常见问题 在使用过程中,可能会遇到各种问题...
4. 数据源配置:如果应用需要数据库连接,需创建并配置数据源,如JDBC资源和连接池。 三、应用部署 1. 模块化部署:支持WAR、EAR、JAR等多种部署方式,满足不同类型的应用需求。 2. 热部署:无需重启服务器,即可...
5. 配置数据源:在Glassfish中,配置与MySQL数据库的连接,如JDBC资源和连接池。 6. 测试应用:访问Web应用的URL,确保部署成功且能正常运行。 通过以上步骤,你将能够在RED HAT 5.5 Linux系统上成功部署一个基于...
- 选择正确的数据库连接池实现,如HikariCP或C3P0,根据应用需求设置合理的连接池大小。 - 监控连接池的使用情况,避免因连接泄露或超时造成的资源浪费。 #### 5. **缓存机制的应用** - 实现有效的缓存策略,...
5. **性能优化**:结合GlassFish和Spring,讨论如何优化应用性能,例如缓存策略、连接池配置、线程池管理等。 6. **故障排查与监控**:介绍在GlassFish中监控Spring应用的方法,包括日志配置、JMX管理、性能指标...