zoukankan      html  css  js  c++  java
  • tomcat7.0连接池配置

    tomcat7.04+MySql的连接

    1.首先在tomcat下的config/context.xml中的<context></context>中加入下面的resource

    <Resource name="jdbc/MySQLDB" auth="Container" type="javax.sql.DataSource"
            driverClassName="com.mysql.jdbc.Driver"
            maxActive="10" maxIdle="5" maxWait="10000"
            username="ruan" password="123456"
            url="jdbc:mysql://localhost:3306/blog" />
    

     2.在web.xml中的<web-app></web-app>中加入以下配置

            <resource-ref>
    		<description>DB Connection</description>
    		<res-ref-name>jdbc/MySQLDB</res-ref-name>
    		<res-type>javax.sql.DataSource</res-type>
    		<res-auth>Container</res-auth>
    	</resource-ref>
    

     3.程序中获取Connection

    public  Connetcion getConnection() {
    		try {
    			Context ctx = new InitialContext();
    			DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/MySQLDB");
    			Connection conn = ds.getConnection();
    			System.out.println(conn);
                            return conn;
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
                    return null;
    	}
    

     连接Sql数据库只需要更改 driverClassName/url

    SQL server2005
    driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    url="jdbc:sqlserver://localhost:1433;databaseName=selectcourse";
    SQL server2000
    driver = "net.sourceforge.jtds.jdbc.Driver";
    url = "jdbc:jtds:sqlserver://127.0.0.1:1433/selectcourse";

    Oracle数据库
    driverClassName="oracle.jdbc.driver.oracledriver"
    url="jdbc:oracle:thin:@localhost:1521:yourdbname" 
  • 相关阅读:
    POJ-2955 Brackets(括号匹配问题)
    NYOJ
    石子合并问题
    hdu 4915 括号匹配+巧模拟
    hdu 4920
    hdu 4911 求逆序对数+树状数组
    hdu 4923 单调栈
    hdu 4930 斗地主恶心模拟
    hdu 4927 组合+公式
    hdu 4925 黑白格
  • 原文地址:https://www.cnblogs.com/skiz/p/2672455.html
Copyright © 2011-2022 走看看