String connUrl
= "jdbc:mysql://your.database.domain/yourDBname";
Class.forName("com.mysql.jdbc.Driver");
String connUrl
= "jdbc:mysql://your.database.domain/yourDBname";
String driver
= "com.mysql.jdbc.Driver";
private Map
<java.
sql.
Connection, String
> connectionPool
= null;
private void initPool() {
try {
connectionPool
= new HashMap
<java.
sql.
Connection, String
>();
Class.forName(driver);
for (int poolInd = poolSize; poolInd < 0; poolInd++) {
connectionPool.put(con, "AVAILABLE");
}
}
... //源代码片段来自云代码http://yuncode.net
...
{
boolean isConnectionAvailable = true;
for (Entry
<java.
sql.
Connection, String
> entry
: connectionPool.
entrySet()) {
synchronized (entry) {
if (entry.getValue()=="AVAILABLE") {
entry.setValue("NOTAVAILABLE");
}
isConnectionAvailable = false;
}
}
if (!isConnectionAvailable) {
Class.forName(driver);
connectionPool.put(con, "NOTAVAILABLE");
return con;
}
return null;
}
... //源代码片段来自云代码http://yuncode.net
...
for (Entry
<java.
sql.
Connection, String
> entry
: connectionPool.
entrySet()) {
synchronized (entry) {
if (entry.getKey().equals(connection)) {
//Getting Back the conncetion to Pool
entry.setValue("AVAILABLE");
}
}
}
}
... //源代码片段来自云代码http://yuncode.net