痛苦的windows20003+oracle10g+tomcat连接池迁移之旅
我的痛苦的windows20003+oracle10g+tomcat连接池迁移之旅
项目开发中完成,在开发环境中是在windowsxp和用自己的连接池开发的,oracle数据库的版本是8。17。
重大问题1:windows2003的问题,微软的正版软件我看也不见的好到那里去。那个windows20003server版本比盗版的还低,装上后还需要激活,激活的工序可是麻烦的要了命。他好像使用了限制一台计算机使用,如果你再这个计算机上安装了这套软件,并且通过电话激活或internet激活方式激活了该操作系统,那么这套操作系统只能再这个计算机上使用了,其他的计算机上不能安装了,安装完了,无法激活!
后来他们销售的通过和微软的多次打电话才解决了这个问题。保证了在那台服务器上能激活。
重大问题2:网上下载的oracle10g无法安装。安装中间报错误:unable to create item in start menu and desktop........,多么郁闷的问题。多次网上查询都没有着相关的问题。找遍了google也没有找到。难道就没有人遇到过。让他们集成的人多次重新安装系统还是不行。到底是那里的问题呢?后来想到了需要用别的软件试验一下,于是拷了一个金山词霸进行安装,奇怪的是他显示的界面都是乱码,最后也报告无法在开始菜单和桌面上创建快捷方式。到底是那里的问题了,开始以为是权限的问题,修改administrator的权限多次,都没解决,最后才知道了是windows本地语言设置的问题。原来是他没有设置好本地的语言。中文的版本,本地语言设置为英文就出现了这么多无法解释的错误。真是要了人的命。不过现在想想,也是,他按照英文找中文的开始菜单,当然找不到了。
重大问题3:
开始搬迁程序了。导入了oracle数据库,从oracle8上备份到oracle10g上到没有什么问题。主要是我们的dba比较厉害。然后开始配置打包程序war文件。放到tomcat上,在tomcat上配置了连接池。修改了程序中获得连接的地方。放上去,发现不行。报错:network adapter........好像是网络没有找到。哦,发现是网线掉了。后来报错,驱动不对,到oracle安装的计算机上找到了他下面的lib\jdbc\的驱动替换掉以前的oracle8的程序。重新部署,报告说找不到驱动。对了把驱动程序到拷贝到了tomcat\common\lib\,然后启动,连接池成功配置。成功登陆了系统。ok?no.最后一个可怕的问题出现了。再读取oracle10g中clob字段的时候报错误。ClassCastException,查看包错误的程序就在:oracle.sql.CLOB clog=(Oracle.sql.CLOB)rs.getClob("clob_text");开始我们认为这是一个多么难解决的问题。我估计可能是那里的转换类型错误了。没想到这个问题害的我整整折腾了2天。
棘手的痛苦的问题4
这个问题确实不那么简单。我开始怀疑是oracle10g驱动的问题。我加载了全部的oracle10g的驱动,尽管网上说如果是在jdk1。4以上的版本,只需要加载其中的一个ojdbc14。jar包。但是事情害是不行。错误仍然,我开始在google上找这个问题。在sun的开坛上的这个帖子给了我很大的帮助:oracle.sql.CLOB+ClassCastException 这个问题网上很多。
http://forum.java.sun.com/thread.jspa?threadID=349880&start=15
这个帖子有各种各样的解决方法。我挨个试验了。
看到了他们使用oracle提供的创建临时clob的方法。
oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_CALL);
依然不行,还是同样的错误发生,我急了,让他打印看看取道的到底是什么对象,缺是java.sql.Clob这个我早知道,打印了了白打,我想把他转换到oracle的clob就是不行。使用创建临时的clob是他的那个连接不能使用。该死的,这个从tomcat5。0中获得的连接池怎么不行呢。后来看到帖子上有人用con的类型转换,转换成oraclejdbcconnnection。于是我也试验了。还不行。后来在其他西班牙的网站上看到了他使用了一个jboss下的包转换wapper,转换成jboss的连接,说是成功了。我开始试验,代码拷贝过来,发现没有jboss的那个common包,于是网上down下来。加载进去,编译通过。放到服务器上。这次不包错误了,但是执行到那里,你等半个小时都过去去。一个字,烂。
马上抛开了这个方法。jboss的东西抛弃掉了。后来在oracle的官方网站上看到熬了oracle公司提供的oracle10g中如何使用jdbc的例子。试验了。还是不行,真不知道他们这些东西是怎么提供处来的。不过在这理看到一个oracle驱动加载的新的方法
import java.sql.Connection;
import java.sql.DriverManager;
import oracle.jdbc.OracleDriver;
import java.util.Properties;
..........
// Load the database details into the variables.
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "tiger";
// Create the properties object that holds all database details
Properties props = new Properties();
props.put("user", user );
props.put("password", password);
props.put("SetBigStringTryClob", "true");
// Load the Oracle JDBC driver class.
DriverManager.registerDriver(new OracleDriver());
// Get the database connection
Connection conn = DriverManager.getConnection( this.url, this.props );
我怀疑props.put("SetBigStringTryClob", "true");东西很有用,于是在tomcat的连接池配置的server.xml中也添加了这个属性参数。配置后,在读取clob的时候,我按照oracle网站提供的直接使用了getString这个方法,庆幸的是ok了,可以读取出来了。
但是更新方法不行,按照他们给提供的。
这是他们给提供的方法:
ClobManipulationIn10g
/*
* @author Savitha
* @version 1.0
*
* Development Environment : Oracle JDeveloper 10g
* Name of the Application : ClobManipulationIn10g.java
* Creation/Modification History :
*
* Savitha 17-Mar-2004 Created.
*/
package oracle.otnsamples.jdbc;
// Java SQL classes
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
// Oracle JDBC driver class
import oracle.jdbc.OracleDriver;
// Java IO classes
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
//Java Util classes
import java.util.Properties;
/**
* This class demonstrates the Oracle JDBC 10g enhanced features for inserting
* and retrieving CLOB data from the database. Using the new features, large
* data of more than 32765 bytes can be inserted into the database using the
* existing PreparedStatement.setString() and PreparedStatement.getString()
* methods.
*/
public class ClobManipulationIn10g {
/* Database Connection object */
private Connection conn = null;
/* Variables to hold database details */
private String url = null;
private String user = null;
private String password = null;
// Create a property object to hold the username, password and
// the new property SetBigStringTryClob.
private Properties props = new Properties();
/* String to hold file name */
private String fileName = null;
/**
* Default Constructor to instantiate and get a handle to class methods
* and variables.
*/
public ClobManipulationIn10g(String fileName) {
this.fileName = fileName;
}
/**
* Main runnable class.
*/
public static void main(String[] args) throws SQLException {
// Instantiate the main class.
C

