Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
DQMP
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data
DQMP
Commits
e04d3559
Commit
e04d3559
authored
Mar 26, 2020
by
赵建伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update codes
parent
9d347b7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
8 deletions
+58
-8
JdbcConnectPool.java
src/main/java/com/gmei/data/dqmp/pool/JdbcConnectPool.java
+6
-8
JdbcUtils.java
src/main/java/com/gmei/data/dqmp/utils/JdbcUtils.java
+52
-0
No files found.
src/main/java/com/gmei/data/dqmp/pool/JdbcConnectPool.java
View file @
e04d3559
...
...
@@ -29,7 +29,6 @@ public class JdbcConnectPool {
for
(
int
i
=
0
;
i
<
Integer
.
valueOf
(
prop
.
getProperty
(
"initSize"
));
i
++)
{
Connection
connection
=
createConnect
();
connList
.
add
(
connection
);
//currentsize++;
}
}
...
...
@@ -40,21 +39,18 @@ public class JdbcConnectPool {
*/
public
static
Connection
getConnect
()
{
Connection
connection
=
null
;
int
connSize
=
connList
.
size
();
if
(
connSize
>
0
)
{
if
(
connList
.
size
()
>
0
)
{
connection
=
connList
.
getFirst
();
connList
.
removeFirst
();
//currentsize--;
}
else
{
while
(
conn
Size
<
Integer
.
valueOf
(
prop
.
getProperty
(
"maxSize"
))){
while
(
conn
List
.
size
()
<
Integer
.
valueOf
(
prop
.
getProperty
(
"maxSize"
))){
connList
.
addLast
(
createConnect
());
//currentsize++;
}
connection
=
getConnect
();
}
requestCount
++;
logger
.
info
(
"requestCount : {}"
,
requestCount
);
logger
.
info
(
"connList size : {}"
,
conn
Size
);
logger
.
info
(
"connList size : {}"
,
conn
List
.
size
()
);
return
connection
;
}
...
...
@@ -66,7 +62,9 @@ public class JdbcConnectPool {
private
static
Connection
createConnect
()
{
Connection
conn
=
null
;
try
{
conn
=
DriverManager
.
getConnection
(
prop
.
getProperty
(
"url"
),
prop
.
getProperty
(
"username"
),
conn
=
DriverManager
.
getConnection
(
prop
.
getProperty
(
"url"
),
prop
.
getProperty
(
"username"
),
prop
.
getProperty
(
"password"
));
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/com/gmei/data/dqmp/utils/JdbcUtils.java
0 → 100644
View file @
e04d3559
package
com
.
gmei
.
data
.
dqmp
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.InputStream
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.util.Properties
;
public
class
JdbcUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JdbcUtils
.
class
);
private
static
Properties
prop
;
static
{
prop
=
getProperties
(
"jdbc.properties"
);
try
{
Class
.
forName
(
prop
.
getProperty
(
"driverClassName"
));
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
logger
.
error
(
e
.
getMessage
());
}
}
public
static
Connection
getConnection
()
throws
Exception
{
Connection
connection
=
DriverManager
.
getConnection
(
prop
.
getProperty
(
"url"
),
prop
.
getProperty
(
"username"
),
prop
.
getProperty
(
"password"
));
return
connection
;
}
/**
* 获取属性文件对象
*
* @param path
* @return
*/
private
static
Properties
getProperties
(
String
path
)
{
Properties
properties
=
new
Properties
();
try
{
InputStream
inputStream
=
JdbcUtils
.
class
.
getClassLoader
().
getResourceAsStream
(
path
);
properties
.
load
(
inputStream
);
inputStream
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
e
.
getMessage
());
}
return
properties
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment