tomcat6.0 + myeclipse6.5 under tomcat data source configuration

(1) Environment: such as a very important question! Different environment, different configurations!

(2) struts package loaded: My MyEclipse6.5 bring him under the load of the struts jar package Error occurred "collections can not find under quickHashMap" abnormal (perhaps meaning, forget the record), then bring him to remove the STRUTS JAR, together with an independent Jar, and will all have to copy added to STRUTS jar works in WEB-INF/lib.

(3) the database connection JAR file COPY separately to the project under WEB-INF/lib and under lib under tomcat.

(4) in the tomcat's conf / under Context.xml changes at one of the <Context> </ Context> add the following code (according to their own situation to be slightly amended):


<Resource name = "sdemo" auth = "Container" type = "javax.sql.DataSource"
maxActive = "100" maxIdle = "30" maxWait = "10000"
username = "sa" password = "xxxxxx" driverClassName = ""
url = "jdbc: sqlserver: / / localhost: 1433; databaseName = afdDemo" />

(5) In the works cited in web.xml:

<!-- A reference to the data source -->

(6) in the projects to use the DBCP had:)

public static Connection getConnection(){
		Connection conn = null;
		try {
			Context initContext = new InitialContext();
			 // Context envContext  = (Context)initContext.lookup("java:/comp/env");
			  DataSource ds = (DataSource)initContext.lookup("java:/comp/env/sdemo"); 

			 conn = ds.getConnection();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
		} catch (SQLException e) {
			// TODO Auto-generated catch block
	     return conn;

(7) at dao class can be directly connected to the call:)

public List<User> selectAll(){
		List<User> list = new ArrayList<User>();
		Connection conn = DBUtil.getConnection();
		if(conn == null){
			System.out.println("conn is null!");
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			pstmt = conn.prepareStatement("select * from [User]");
			rs = pstmt.executeQuery();
			User user = new User();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			try {
				if(rs != null){
				if(pstmt != null){
				if(conn != null){
			} catch (SQLException e) {
				// TODO Auto-generated catch block
		return list;

分类:Java 时间:2009-03-03 人气:1077
blog comments powered by Disqus


  • Hibernate support package DBCP database connection pool configuration 2009-04-09

    Hibernate support package DBCP database connection pool configuration. A brief description of the configuration process: (Just a personal feeling, if questions are welcome to show) Required packages: Commons-Pool (download Address: http://jakarta.apa

  • DBCP database connection pool 2010-06-24

    Concepts: database connection pool for distribution, management and release database connections, it allows applications to reuse an existing database connection, instead of re-establishing a connection; release of free time over the maximum idle tim

  • Dbcp database connection pool with c3p0 using 2011-08-29

    As we all know, whether it is B / S or C / S applications, and databases are inevitably have to deal with. Exchange with the database Each process, often requires a lot of connections. For a large-scale applications, often need to deal with tens of m

  • How to connect sql server database connection pool configuration Tomcat 2010-02-24

    How to connect SQL Server database (Tomcat connection pool configuration) (reproduced) Source: Version is relatively new, on-line many are saying is Tomcat 4, this is 5.0. How to connect SQL Se

  • DBCP database connection failure solution (Io exception: Connection reset) 2010-02-23

    Many commented that the DBCP web there are many BUG, but did not specify what is BUG, only a few people say that if for some reason cut off the database after the connection is via DBCP connection failure, but not to re-take. Some time will be report

  • Sql Server Database guide cross-server data. 2011-05-17

    1, a new connection to the server, connect to the server you want to import IP address (or machine name) 2, click on security, establish a connection with this security context, enter the database server user name and password 3, select to export the

  • Forced to shut down the SQL Server database connection 2011-05-16

    1 issues into the In SQL Server backup / restore / separation / offline / delete the specified database, if other users are using this database, SQL Server data in order to prevent abnormal, error and will terminate your operation. Of course, SQL 200

  • sql server database connection string 2011-07-04

    App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="sqlconn" connectionString="Data Source=7806221B71404F3\SQLEXPRESS;Initial Catalog=mydb; User"/&g

  • Get a database connection (in the normal way and the way the data source) 2010-12-15

    Step One: Create a JavaWeb works, called DBConnPrjTest (this project name is variable) Step Two: In DBConnPrjTest \ WebRoot \ WEB-INF \ lib, add the following package and loaded into the project: commons-logging-1.1.1.jar ojdbc14.jar: oracle database

  • Database connection pool implementation principle 2010-09-21

    Database connection pool implementation principle Implementation principle is to use dynamic proxy technology Write connection pool required to achieve java.sql.DataSource interface DataSource interface defines two overloaded getConnection method: Co

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.223 (s). 13 q(s)