Saturday, December 10, 2011

查詢 informix sequence的值

通常,會在資料庫 table 的 Primary Key 欄位,用資料庫預設的流水號,

指令為:

CREATE SEQUENCE table_seq;

在塞值時,就會用 table_seq.nextval ,取得該流水號

INSERT INTO table ( index, name, value )

VALUES( table_seq.nextval , ‘fooName’, ‘fooValue' )

但當有需求是,要把新增的這一筆資料,再query出來,秀在畫面時

可以用新增的資料當作查詢條件,把該筆資料查出來

但,不能保證,只會查該筆資料,有可能會有重覆類似的資料查出來

這時,最保險的做法是:如果我能知道,資料庫產生的sequence的值,去做查詢

做法( 以informix為例 ):

//從 systables 查出 流水序號的

String nextValSql =

"SELECT table_seq.nextval FROM systables WHERE tabid=1" ; 

int sequence_number = getJdbcTemplate().queryForInt(nextValSql);

記得:流水號的型別是 int

Monday, December 5, 2011

解決 java.net.UnknownHostException

<Uncaught Throwable in processSockets
weblogic.utils.NestedError: This address was valid earlier, but now we get: .
weblogic.utils.NestedError: This address was valid earlier, but now we get:
    at weblogic.rjvm.JVMID.address(JVMID.java:560)
    at weblogic.rjvm.RJVMManager.record(RJVMManager.java:153)
    at weblogic.rjvm.RJVMManager.findOrCreateInternal(RJVMManager.java:289)
    at weblogic.rjvm.RJVMManager.findOrCreateRemote(RJVMManager.java:139)
    at weblogic.rjvm.ConnectionManagerServer.handleIdentifyResponse(ConnectionManagerServer.java:621)
    Truncated. see log file for complete stacktrace
Caused By: java.net.UnknownHostException: RISCLT-4
    at java.net.InetAddress.getAllByName0(InetAddress.java:1157)
    at java.net.InetAddress.getAllByName(InetAddress.java:1083)
    at java.net.InetAddress.getAllByName(InetAddress.java:1019)
    at java.net.InetAddress.getByName(InetAddress.java:969)
    at weblogic.rjvm.JVMID.address(JVMID.java:553)
    Truncated. see log file for complete stacktrace
>
解決方法:在 C:\Windows\System32\drivers\etc\hosts
將 #127.0.0.1 ---> 的 「#」 拿掉。
再新增 RISCLT-4 這個新的domain name 和 ip,如:
        192.160.2.1    RISCLT-4