5.SQLServer DataSource and SingleTon:
import net.sourceforge.jtds.jdbcx.*;
import java.sql.*;
import javax.sql.*;
public class SqlserverSingletonDataSource {
static private JtdsDataSource ds;
private Connection con;
private SqlserverSingletonDataSource() {
try {
ds = new JtdsDataSource();
ds.setServerName("localhost");
ds.setDatabaseName("pubs");
ds.setUser("sa");
ds.setPassword("");
}
catch (Exception e) {
}
}
public static Connection getConnection() throws Exception {
if (ds == null) {
new SqlserverSingletonDataSource();
}
Connection con =null;
try {
con = ds.getConnection();
} catch (SQLException ex) {
}
return con;
}
}
版权保护原文出处:http://www.mark-to-win.com/JavaBeginner/JavaBeginner10_web.html#SQLServerDataSourceandSingleTon