昨天的問題,終于知道了,是oracle8搞的鬼,懶的再去找什么驅動了。便想起了python
幸好張駿 的幫忙,讓我從一知半解到寫出代碼。
用python的代碼明顯簡潔多了,而且我喜歡代碼的靈活。
import cx_Oracle
def parse():
'''generate the content html'''
sql = '''select t.bz_code code, t.bz_title title, t.bz_content content
from bz_czzs t
order by t.bz_code'''
connection = cx_Oracle.connect( 'etasadmin/etasadmin@zhongju' )
cursor = connection.cursor()
cursor.execute(sql)
item=cursor.fetchone()
i=1;
print 'begin'
while item:
i+=1
print 'parsing ',i,' item....'
writeContent(item[0],item[1],str(item[2]))
item=cursor.fetchone()
print 'end'
def writeContent(code,title,content):
filename='D:\\workspace\\style\\test\\content_body.html'
s = getContent(code,title,content)
out = open(filename,'a')
out.write(s)
out.flush()
out.close()
if __name__=='__main__':
print 'parse..................'
parse()
print 'end'
看樣子,要好好學習它了。
python 真棒 o_o
注:問題已經解決,oracle8的問題,處理lob需要oci
昨天處理數據的時候,遇到oracle的clob的問題。解決不了,郁悶。
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("content");
Reader reader = rs.getCharacterStream("content");
reader.read(c);
System.out.println("content:" + new String(c));
if (null != clob && 0 < clob.length())
System.out.println("content:" +
clob.getSubString((long) 1, (int) clob.length()));
else
System.out.println("nop");
在這下面兩處,總是報錯。
和
clob.getSubString((long) 1, (int) clob.length())
錯誤如下:
java.io.IOException: 類型長度大于最大值
at oracle.jdbc.dbaccess.DBError.SQLToIOException(DBError.java:716)
at oracle.jdbc.driver.OracleClobReader.needChars(OracleClobReader.java:222)
at oracle.jdbc.driver.OracleClobReader.read(OracleClobReader.java:163)
at java.io.Reader.read(Reader.java:100)
at com.jxlt.db.parse.Parse.parse(Parse.java:46)
at com.jxlt.db.parse.Parse.main(Parse.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
google了一下 ,很多人說是驅動的問題,我用了oracle 9自己帶的class12&ojdbc14.jar都不行,到oracle站點下了 oralce 10g的驅動,同樣也是。
申請了個blog :)thx blogjava!
以前的一篇收藏的文章,放這里來
----------------------------------------------
客戶提出的需求是能同時實現
非實時查詢
實時查詢
沒有用過實現兩臺服務器的連接,google了一下。正好有:)留著
url:http://www.softhouse.com.cn/html/200411/2004113009170200002474.html
如何連接兩臺Oracle服務器
軟件環境:
1、Windows NT4.0+ORACLE 8.0.4
2、ORACLE安裝路徑為:C:\ORANT
3、服務器A、服務器B,均裝有NT 4.0中文版
實現方法:
1. 假設A地址192.1.1.1,B地址192.1.1.2
2. A、B上配置好TCP/IP,互相Ping通。
3. 配置init.ora文件,若global_name = true的話,database link 的名字必須同遠程機的實例名相同,
為簡便起見,請將global_name 設為 false。
4. 在服務器上配置tnsnames.ora,將Remote機器的地址(IP)信息加入本地的tnsnames.ora
A服務器:
TNSA_B =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = 192.1.1.2)
(Port = 1521)
)
)
(CONNECT_DATA = (SID = ORCL)
)
)
B服務器:
TNSB_A =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = 192.1.1.1)
(Port = 1521)
)
)
(CONNECT_DATA = (SID = ORCL)
)
)
5. 在 SQL*Plus 或其它工具中創建數據庫鏈接
A服務器:create public database link A_TO_B connect to tmp identified by tmp using 'TNSA_B';
B服務器:create public database link B_TO_A connect to tmp identified by tmp using 'TNSB_A';
說明:
tmp是一個臨時用戶,A服務器、B服務器上均有,它的作用是提供鏈接的目的地,
假如:
B服務器上有user1、user2、tmp三個用戶,user1和user2把他們想要對外公開的表的權限授給tmp用戶,
那么,所有能通過database link連接到tmp用戶上的人就可以直接訪問user1、user2上的已授權表了。
6. 建立database link以后,請用這種格式select * from table_name@database_link_name 的方式訪問
如:在A服務器上想訪問B服務器上user1用戶table1表的內容(A到B的連接為A_TO_B),則
SQL> select * from table1@A_TO_B;
7. 如果Oracle版本為7.3,則數據庫聯接寫法如下:
A服務器:create public database link A_TO_B connect to tmp identified by tmp using 't:192.1.1.2:orcl';
B服務器:create public database link B_TO_A connect to tmp identified by tmp using 't:192.1.1.1:orcl';