package com.fh.util.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 类名称:SingletonJDBCConnection 测试链接数据库
* 创建人:toshiba
* 创建时间:2017年9月2日16:11:12
* @version
*/
public class SingletonJDBCConnection {
private static SingletonJDBCConnection instance;
private SingletonJDBCConnection() {
super();
}
public static SingletonJDBCConnection getInstance(){
if(null==instance){
synchronized (SingletonJDBCConnection.class) {
if(null==instance){
instance = new SingletonJDBCConnection();
}
return instance;
}
}
return instance;
}
private static final String URL="jdbc:mysql://127.0.0.1:3306/*****?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8";
private static final String USERNAME="****";
private static final String PASSWORD="****";
private Connection conn=null;
protected Connection getConnection(){
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn =DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
懒汉式单利同步链接jdbc数据库
最新推荐文章于 2020-01-01 20:27:00 发布