I would not recommend this approach. You are basically creating a connection and hanging on it it. I'm not in love with your pattern, but something like this would be better:
public class DataTransaction {
private final static BasicDataSource dataSource;
static {
dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/registrationtest");
dataSource.setUsername("root");
dataSource.setPassword("root");
dataSource.setMaxActive(100);
dataSource.setMaxWait(10000);
dataSource.setMaxIdle(10);
}
private DataTransaction() {
}
public static DataSource getDataSource() {
return dataSource;
}
}
Further, I would not hardcode any of the DataSource parameters, but rather initialize the DataSource from a properties file.