public class SqlMsDataSource implements DataSource{
private static SqlMsDataSource instance = new SqlMsDataSource();;
private SqlMsDataSource() {
}
public static SqlMsDataSource getInstance() {
return instance;
}
private static LinkedList<Connection> pool = new LinkedList<Connection>();
private static String DriverName = " ";
private static String url = " ";
private static String username = " ";
private static String password = " ";
private static Logger logger = Logger.getLogger(SqlMsDataSource.class);
private static Connection conn =null;
static{
try {
ResourceBundle res = ResourceBundle.getBundle("uh");
url = res.getString("msssql.url");
username = res.getString("msssql.username");
password = res.getString("msssql.password");
DriverName = res.getString("msssql.driver");
Class.forName(DriverName);
Connection conn = DriverManager.getConnection(url, username, password);
logger.info("mssql connect successfully");
} catch (Exception e) {
logger.info("mssql connect fail");
e.printStackTrace();
throw new RuntimeException("mssql connect fail");
}
}
@Override
public Connection getConnection() throws SQLException {
if(conn == null || conn.isClosed()) {
conn = DriverManager.getConnection(url, username, password);
}
return conn;
}
@Override
public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}
@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
// TODO Auto-generated method stub
return null;
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
// TODO Auto-generated method stub
return null;
}
}