1.Oracle与SQL Server在配置连接池时的区别:
Tomcat配置文件中
Oracle的配置方法
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@172.28.122.49:1521:cpdb</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
SQL Server的配置方法
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
注意:
SQL Server包的取得方式
从http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&DisplayLang=en#filelist下载"Microsoft SQL Server 2000 Driver for JDBC",并安装,得到msbase.jar,mssqlserver.jar和msutil.jar三个文件,将三个文件COPY到TOMCAT 4.1下common/lib文件夹中
Oracle包的取得方式
将/ORANT/jdbc/lib/classes12.jar COPY到TOMCAT 4.1下common/lib文件夹中
2.Oracle与SQL Server在使用JDBC时的区别:
Oracle
String url_ = "172.28.122.49:1521:cpdb";
String id_ = "cu01";
String pass_ = "abc";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@" + url_, id_, pass_);
SQL Server
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://BLUESKY:1433;User=sa;Password=sa;DatabaseName=sitedb);
Class.forName(driverName);
Connection conn = DriverManager.getConnection(connURL);
3.例子说明
例子中:tomcattry.xml是Tomcat的配置文件, sample是一个连接池servlet端代码(通过comming.html启动servlet)
本例子环境
OS: Windows2000
JDK: 1.4.2_04
IDE: Eclipse3.0
Web Server: Tomcat4.1.27
Database: Oracle9i
数据库表结构
表名:
test
结构:
USERNAME NOT NULL VARCHAR2(10)
PASSWORD VARCHAR2(10)
建表语句:
create table test(username varchar(10) primary key,password varchar(10));