happyfish

BlogJava 首页 新随笔 联系 聚合 管理
  38 Posts :: 1 Stories :: 62 Comments :: 0 Trackbacks
/* MySQL With MM JDBC */
driver = "org.gjt.mm.mysql.Driver";
url = "jdbc:mysql://localhost/junit_test";
/*Sybase jconnect2.jar */
url = "jdbc:sybase:Tds:host:port";
driver = "com.sybase.jdbc2.SybDriver";
/*Oracle JDBC Thin Driver classes12.zip */
url = "jdbc:oracle:thin:@host:port:sid";
driver = "oracle.jdbc.driver.OracleDriver";
/*Oracle OCI Driver classes12.zip*/
url = "jdbc:oracle:thin:@host:port:sid";
driver = "oracle.jdbc.driver.OracleDriver";
/* OpenBase OpenBaseJDBC.jar (download from www.openbase.com) */
url = "jdbc:openbase://host/database";
driver = "com.openbase.jdbc.ObDriver";
/* MySQL Connector/J from MySql (www.mysql.com)
jdbc classes: mysql-connector-java-2.0.14-bin.jar (download from www.mysql.com) */
url = "jdbc:mysql://host/database";
driver = "com.mysql.jdbc.Driver";
/*JDBC Drivers from Microsoft MSSQL 2000
jdbc classes: msbase.jar, sqlserver.jar, msutil.jar */
url = "jdbc:microsoft:sqlserver://host:port";
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
/*JSQLConnect from JDBC Drivers from Microsoft MSSQL 2000
jdbc classes: msbase.jar, sqlserver.jar, msutil.jar */
url = "jdbc:microsoft:sqlserver://host:port";
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
/*DB2 Universal JDBC Driver from IBM
jdbc classes: db2java.zip */
url = "jdbc:db2:host";
driver = "COM.ibm.db2.jdbc.app.DB2Driver";


可以用开源项目实现轻量级连接池
import com.devdaily.opensource.database.DDConnectionBroker;
String driver = null;
String url = null;
String username = null;
String password = null;
int minConnections = 0;
int maxConnections = 0;
long timeout = 0;
long leaseTime = 0;
String logFile = null;
DDConnectionBroker broker = null;

void setUp() {
/* MySQL With MM JDBC */
driver = "org.gjt.mm.mysql.Driver";
url = "jdbc:mysql://localhost/junit_test";
/*Sybase jconnect2.jar */
url = "jdbc:sybase:Tds:host:port";
driver = "com.sybase.jdbc2.SybDriver";
/*Oracle OCI Driver classes12.zip*/
url = "jdbc:oracle:thin:@host:port:sid";
driver = "oracle.jdbc.driver.OracleDriver";
/* OpenBase OpenBaseJDBC.jar (download from www.openbase.com) */
url = "jdbc:openbase://host/database";
driver = "com.openbase.jdbc.ObDriver";
/* MySQL Connector/J from MySql (www.mysql.com)
jdbc classes: mysql-connector-java-2.0.14-bin.jar (download from www.mysql.com) */
url = "jdbc:mysql://host/database";
driver = "com.mysql.jdbc.Driver";
/*JDBC Drivers from Microsoft MSSQL 2000
jdbc classes: msbase.jar, sqlserver.jar, msutil.jar */
url = "jdbc:microsoft:sqlserver://host:port";
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
/*JSQLConnect from JDBC Drivers from Microsoft MSSQL 2000
jdbc classes: msbase.jar, sqlserver.jar, msutil.jar */
url = "jdbc:microsoft:sqlserver://host:port";
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
/*DB2 Universal JDBC Driver from IBM
jdbc classes: db2java.zip */
url = "jdbc:db2:host";
driver = "COM.ibm.db2.jdbc.app.DB2Driver";
/*Oracle JDBC Thin Driver classes12.zip */
url = "jdbc:oracle:thin:@host:port:sid";
driver = "oracle.jdbc.driver.OracleDriver";

username = "";
password = "";
minConnections = 1;
maxConnections = 1;
timeout = 100;
leaseTime = 60000;
logFile = "queryconn.log";
broker = null;
}

try {
// construct the broker
broker = new DDConnectionBroker(driver,
url,
username,
password,
minConnections,
maxConnections,
timeout,
leaseTime,
logFile);
}
catch (SQLException se) {
// could not get a broker; not much reason to go on
System.err.println(se.getMessage());
System.err.println("Could not construct a broker, quitting.");
System.exit( -1);
}

db2有4种jdbc连接方式,我用的是type4(只支持8以上的版本),也是直接通过jdbc连接,其他的客户端好象还要安装客户端工具,
type4的JDBC驱动:com.ibm.db2.jcc.DB2Driver
url的格式:jdbc:db2://{host}:50000/{database name}
包名:db2jcc.jar
还有连接程序一定要用ibm的jdk来运行,要不然出错!
posted on 2005-04-29 11:14 小鱼儿 阅读(692) 评论(0)  编辑  收藏 所属分类: The Persistence Layer

只有注册用户登录后才能发表评论。


网站导航: