1
2
3
|
Class.forName( "com.mysql.jdbc.Driver" ); String url= "jdbc:mysql://localhost:3306/test" ; Connection connection = DriverManager.getConnection(url, "root" , "123" ); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<Resource name= "mydataSource" auth= "Container" type= "javax.sql.DataSource" url= "jdbc:mysql://localhost:3306/test" driverClassName= "com.mysql.jdbc.Driver" password= "123" username= "root" initialSize= "2" maxActive= "3" maxIdle= "1" minIdle= "1" maxWait= "10000" removeAbandoned= "true" logAbandoned= "true" removeAbandonedTimeout= "60" timeBetweenEvictionRunsMillis= "900000" minEvictableIdleTimeMillis= "1800000" numTestsPerEvictionRun= "100" validationQuery= "select count(0) from dual" poolPreparedStatements= "true" maxOpenPreparedStatements= "100" /> |
1
2
3
|
Context it = new InitialContext(); DataSource ds = (DataSource) it.lookup( "java:comp/env/mydataSource" ); Connection conn = ds.getConnection(); |