- 浏览: 202169 次
- 性别:
- 来自: 青岛
最新评论
-
sunysh005:
界面太丑了,功能没有问题
SWFUpload+commons-fileupload 上传文件 -
liwh1989:
liwh1989 写道
SWFUpload+commons-fileupload 上传文件 -
liwh1989:
...
SWFUpload+commons-fileupload 上传文件 -
liwh1989:
SWFUpload+commons-fileupload 上传文件 -
貌似掉线:
已用上。多谢!
native2ascii的 java实现
类结构
org
|_demo
|_dao
|_datasource
|_ConnectionTools.java
|_DataSourceFactory.java
|_PropertyDataSourceFactory.java
package org.demo.dao.datasource; import javax.sql.DataSource; /** * 数据源工厂 * @author * @date 2010-6-18 * @file org.demo.dao.datasource.DataSourceFactory.java */ public interface DataSourceFactory { // 默认数据源名称 String defaultDataSourceName = "default"; /** * 返回默认数据源 * @return dataSource or null */ DataSource getDataSource(); /** * 返回指定数据源 * @return dataSource or null */ DataSource getDataSource(String dataSourceName); }
package org.demo.dao.datasource; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; /** * 基于属性文件的数据源工厂 * @author * @date 2010-6-18 * @file org.demo.dao.datasource.PropertyDataSourceFactory.java */ public class PropertyDataSourceFactory implements DataSourceFactory{ // properties private static final String defaultFileName = "datasource.properties"; protected Map<String,Properties> datasourceParams = new HashMap<String,Properties>(); protected Map<String,DataSource> datasourceMap = new HashMap<String,DataSource>(); /** * 构造函数 * @throws RuntimeException * If the datasource.properties could not be found or property key is illegal. * @throws IOException * If could not load properties from datasource.properties */ public PropertyDataSourceFactory()throws IOException{ this(defaultFileName); } /** * 构造函数 * @param fileName * The resource name * @throws RuntimeException * If the resource could not be found or property key is illegal. * @throws IOException * If could not load properties from resource */ public PropertyDataSourceFactory(String fileName)throws IOException{ // getResourceAsStream InputStream in = PropertyDataSourceFactory.class.getClassLoader() .getResourceAsStream(fileName); if(in == null){ throw new RuntimeException("The [" + fileName + "] is not found."); } // load properties from stream Properties props = new Properties(); try { props.load(in); } catch (IOException e){ throw new IOException("Could not load [" + fileName + "] config file.",e); } // analyze properties Iterator<Object> it = props.keySet().iterator(); while(it.hasNext()){ String key = (String)it.next(); String value = props.getProperty(key); int dotIndex = key.indexOf('.'); if(dotIndex < 1){ // dotIndex must > 1 [default.driver=oracle.jdbc.driver.OracleDriver] throw new RuntimeException("Illegal property key [" + key + "]."); } String datasourceName = key.substring(0,dotIndex); key = key.substring(dotIndex + 1); Properties params = datasourceParams.get(datasourceName); if(params == null){ params = new Properties(); datasourceParams.put(datasourceName, params); } params.put(key,value); } } /** * 返回默认数据源 * @return dataSource or null */ public DataSource getDataSource(){ return getDataSource(defaultDataSourceName); } /** * 返回指定数据源 * @param dataSourceName * The dataSource name * @return dataSource or null */ public DataSource getDataSource(String dataSourceName){ DataSource datasource = datasourceMap.get(dataSourceName); if(datasource != null){ return datasource; } datasource = createDataSource(datasourceParams.get(dataSourceName)); if(datasource != null){ datasourceMap.put(dataSourceName, datasource); } return datasource; } /** * 创建一个数据源 * @param props * @return dataSource or null * @throws IllegalArgumentException * If props is null */ protected DataSource createDataSource(Properties props){ if(props == null){ throw new IllegalArgumentException("props can not be null."); } if(props.getProperty("jndiName") != null){ DataSource jndiDataSource = getJndiDataSource(props); if(jndiDataSource != null){ return jndiDataSource; } } BasicDataSource dataSource = new BasicDataSource(); // required dataSource.setDriverClassName(props.getProperty("driverClassName")); dataSource.setUrl(props.getProperty("url")); dataSource.setUsername(props.getProperty("username","")); dataSource.setPassword(props.getProperty("password","")); // options dataSource.setInitialSize(Integer.parseInt(props.getProperty("initialSize","3"))); dataSource.setMaxActive(Integer.parseInt(props.getProperty("maxActive", "10"))); dataSource.setMaxIdle(Integer.parseInt(props.getProperty("maxIdle","5"))); dataSource.setMaxWait(Long.parseLong(props.getProperty("maxWait","-1"))); dataSource.setValidationQuery(props.getProperty("validationQuery")); return dataSource; } /** * 返回 jndi 数据源 * @param props * @return dataSource or null */ protected DataSource getJndiDataSource(Properties props){ String jndiName = props.getProperty("jndiName"); String inContainer = props.getProperty("inContainer"); String prefix = "java:comp/env/"; if(!jndiName.startsWith(prefix) && "true".equals(inContainer)){ jndiName = prefix + jndiName; } // DataSource jndiDataSource = null; Context context = null; try{ context = new InitialContext(props); jndiDataSource = (DataSource)context.lookup(jndiName); if(jndiDataSource != null){ return jndiDataSource; } } catch (NamingException e){ // ignore } finally { try{ if(context != null){ context.close(); } } catch (NamingException e){ // ignore } } return jndiDataSource; } }
package org.demo.dao.datasource; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.sql.DataSource; /** * 连接工具 * @author * @date 2010-6-18 * @file org.demo.dao.datasource.ConnectionTools.java */ public abstract class ConnectionTools { // 数据源工厂 protected static DataSourceFactory _factory; static { try { _factory = new PropertyDataSourceFactory(); } catch(IOException e){ e.printStackTrace(); } } /** * 返回默认数据源的连接 * @return connection or null */ public static Connection getConnection(){ return getConnection(DataSourceFactory.defaultDataSourceName); } /** * 返回指定数据源的连接 * @param dataSourceName * The dataSource name * @return connection or null */ public static Connection getConnection(String dataSourceName){ DataSource datasource = _factory.getDataSource(dataSourceName); Connection conn = null; if(datasource != null){ try{ conn = datasource.getConnection(); } catch (SQLException e){ e.printStackTrace(); } } return conn; } /** * 关闭连接对象 * @param rset * ResultSet * @param stmt * Statement * @param conn * Connection */ public static void close(ResultSet rset,Statement stmt,Connection conn){ try { if (rset != null) rset.close(); } catch (Exception e) {} try { if (stmt != null) stmt.close(); } catch (Exception e) {} try { if (conn != null) conn.close(); } catch (Exception e) {} } }
# datasource.properties
# oracle default.driverClassName=oracle.jdbc.driver.OracleDriver default.url=jdbc:oracle:thin:@localhost:1521:test default.username=scott default.password=tiger #
package org.demo.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import org.demo.dao.datasource.ConnectionTools; // // library dependencies: // * commons-dbcp-1.3.jar [http://commons.apache.org/dbcp/download_dbcp.cgi] // * commons-pool-1.5.4.jar [http://commons.apache.org/pool/download_pool.cgi] // /** * @author * @date 2010-6-18 * @file org.demo.dao.Main.java */ public class Main { /** * @param args */ public static void main(String[] args)throws Exception{ // get connection Connection conn = ConnectionTools.getConnection(); // execute business operations Statement stmt = null; ResultSet rset = null; stmt = conn.createStatement(); rset = stmt.executeQuery("select 1 from dual"); int cols = rset.getMetaData().getColumnCount(); while(rset.next()){ for(int i=1;i<=cols;i++){ System.out.print("\t" + rset.getObject(i)); } System.out.println(""); } // close connection ConnectionTools.close(rset, stmt, conn); } }
发表评论
-
ubuntu 里安装 db2
2011-04-11 16:17 5257# 下载 http://www-01.ibm.com ... -
几个小算法题
2011-04-03 13:40 1118/** * 数字三角 * 当 n == 7 时输 ... -
获取 SkyDrive 的文件外链固定地址
2011-04-03 11:47 1444javascript: var id = window.se ... -
常用知识记录
2011-04-02 17:25 1606sql 部分 1. 查询已创建的数据库 // ... -
Java 与 C++ 在表达式运算上的一点异同
2010-12-25 00:24 12641. java public class Main{ ... -
SWFUpload+commons-fileupload 上传文件
2010-12-17 19:20 10968说明:使用SWFUpload 上传文件,可在客户端校验文件大小 ... -
在 ubuntu 下搭建 ftp 服务端 [ vsftpd ]
2010-11-16 20:11 1873vsftpd 1. 安装 ftp 服务端 ... -
Tomcat 常用操作
2010-11-16 13:47 2642tomcat 常用操作 1. 安装 tomcat 1.1 ... -
在 ubuntu 下搭建 svn 服务端
2010-11-13 20:43 2972参考: http://wiki.ubunt ... -
正则表达式常用功能代码
2010-11-02 19:37 12951. 校验 /** * 校验 email * @pa ... -
三种常见的排序方法[选择,冒泡,快速]
2010-10-17 17:51 1093public class Main{ public ... -
Filter 常用代码
2010-10-12 22:50 12021. 压缩 Filter // GZIPFilter.jav ... -
log4j 常用配置代码
2010-10-12 14:35 1370Reference library: commons-log ... -
计算组合数并输出
2010-09-14 09:35 5585问题描述:计算一组数据的组合数并输出 例如:输入1,2,3 ... -
native2ascii的 java实现
2010-09-13 13:49 3865描述:简单模拟JDK自带的 native2ascii.exe ... -
计算全排列
2010-09-13 09:04 1577问题描述:计算一组数 ... -
Java常用功能代码
2010-06-10 14:33 58771. 屏幕截图 public static ... -
一个关于组合数的问题
2010-05-03 20:09 11591. 题目来源 未解之谜俱 ... -
Java常用功能代码[ 2 ]
2010-04-27 17:35 13871. 加载所有 jar 包中同名的配置文件 /** * ... -
程序员学习之路
2010-04-14 20:59 14661. JavaScript 1.1 全方位、多角度学习Jav ...
相关推荐
apache commons dbcp api_zh
Apache Commons DBCP 软件实现数据库连接池
org.apache.commons.dbcp.BasicDataSource的解决方法,commons-dbcp.jar、commons-pool.jar
与Apache Commons DBCP的使用有关的问题应张贴到。 在哪里可以获得最新版本? 您可以从我们的下载源代码和二进制文件。 或者,您可以从中央Maven存储库中提取它: < groupId>org.apache.commons < artifactId>...
Apache Jakarta Commons DBCP supports JDK 1.3 (JDBC 2.0) and JDK 1.4-1.5 (JDBC 3.0). JDK 1.6 (JDBC 4.0)
赠送jar包:commons-dbcp-1.4.jar; 赠送原API文档:commons-dbcp-1.4-javadoc.jar; 赠送源代码:commons-dbcp-1.4-sources.jar; 赠送Maven依赖信息文件:commons-dbcp-1.4.pom; 包含翻译后的API文档:commons-...
Maven坐标:org.apache.commons:commons-dbcp2:2.2.0; 标签:apache、dbcp2、commons、jar包、java、API文档、中文版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性...
Apache Commons IO 功能是使用 Apache Commons Pool简介 Apache Commons DBCP使用
介绍了Apache Jakarta Commons 项目下Java组件,如FileUpload, HttpClient, DBCP,BeanUtils,Logging,Lang, 以及 Collections,Codec等,是学习和使用Apache Jakarta Commons良好的参考使用手册。
org.apache.commons.dbcp的资源包
DBCP(DataBase Connection Pool)是 apache common上的一个 java 连接池项目,也是 tomcat 使用的连接池组件,依赖 于Jakarta commons-pool 对象池机制,DBCP可以直接的在应用程序中使用。 使用DBCP会用到commons-...
com.springsource.org.apache.commons.dbcp-sources-1.2.2.osgi.jar源码 jar包
整个系统都没有错误,但是在发布运行后,控制台上却抛出了这样的异常: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
commons-dbcp2-2.7.0.jar用于Java连接数据库的使用,方便操作,简化代码,对于新入手学习JDBC的朋友可以尝试使用,idea 用DBCP连接数据库时必备jar包
org.apache.commons.dbcp.BasicDataSource类所需要的3个jar包commons-collections.jar,commons-dbcp.jar,commons-pool.jar
Apache Commons DBCP软件实现数据库连接池 org.apache.commons/commons-dbcp2/2.8.0/commons-dbcp2-2.8.0.jar
Apache commons dbcp 1.2.2 连接池 API文档
apache-commons下全部官方源码和官方API文档,其中有: commons-beanutils-1.8.0 commons-codec commons-collections commons-dbcp commons-dbutils commons-fileupload commons-io commons-lang commons-lang3 ...
commons-dbcp-1.2.jar包是一款主流的数据库连接池之一(DBCP,c3p0,proxool),如果缺少了这个commons-dbcp.jar包,那将无法对数据库连接池进行正常使用,需要此款commons-dbcp-1.2.jar包的朋友们欢迎前来下载使用。...
com.springsource.org.apache.commons.dbcp_1.2.2.osgi.jar