<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-25  評論-6  文章-0  trackbacks-0
      2006年6月21日

    Question:
    The restore command works fine, but while attempting the rolforward of the sql logs, it complains about database falling short on bufferpool,and then terminates the rollforward process. One close look at the db2diag.log file, I noticed that db2 tried to start the database with the hidden bufferpool. But, apparently, that hidden bufferpool was pretty small to rollforward the logs and bring it online.

    I cannot reduce the bufferpool size as the database cannot be connected to.I cannot connect to the database as it is in rollforward pending state. I cannot rollforward the database, as it's not happy with the size of the *hidden* bufferpool and terminates.

    Answer:

    db2set DB2_OVERRIDE_BPF=50000

    This will bring up all configured bufferpools using 50000 pages each. You
    can choose a smaller/larger value that is suitable for your number of
    bufferpools and available system memory. You can also configure each
    bufferpool individually if you want

    値: 正數のページ數
    ???? OR
    ?<entry>[;<entry>...] (<entry>=<バッファー?プール ID>,<ページ數> )

    There is sitiuation that above solution does not work.

    				When you try to create a bufferpool or alter a bufferpool to a
    very large size and there is not enough memory in the system
    , DB2 may occupies all pagespace and overrall performance of
    the system become slow and may get hang at last because no
    pagespace is available. Then after you connect the database
    next time, DB2 will do crash recovery and still try to
    allocate memory for this big bufferpool and occupy all
    pagespace again. when you specify DB2_OVERRIDE_BPF parameter
    to override bufferpool size, it doesn't take effect in this
    situation. This is becasue DB2_OVERRIDE_BPF only applies for
    bufferpools that already exist at startup, and not to
    bufferpools that are created during crash recovery or roll
    forward. We will fix this problem and check DB2_OVERRIDE_BPF
    registry when creating bufferpools during crash recovery or
    roll forward. This problem only occurs in a 64 bit instance.
    
    		

    Local fix

    				You can use db2iupdt -w 32 <INSTNAME> to update the instance to
    a 32 bit instance, then you can connect to the database
    succefully. After that, use db2iupdt -w 64 <INSTNAME> to update
    the instance to 64 bit again. Please take a backup at this
    point, so we don't have to roll forward through bufferpool
    creation that fails if we need restore and roll forward
    database.
    
    		

    Problem summary

    				Users Affected:
    All users using 64 bit instance
    Problem Description:
    When you try to create a bufferpool or alter a bufferpool to a
    very large size and there is not enough memory in the system
    , DB2 may occupies all pagespace and overrall performance
    of the system become slow and may get hang at last
    because no pagespace is available. Then after you connect the
    database at next time, DB2 will do crash recovery and still try
    to allocate
    memory for this big bufferpool and occupy all pagespace again.
    In this situation, when you specify DB2_OVERRIDE_BPF parameter
    to override bufferpool size, it doesn't take effect in this
    situation. This
    is becasue DB2_OVERRIDE_BPF only applies for bufferpools that
    already exist at startup, and not to bufferpools that are
    created during crash recovery or roll forward. We will fix
    this problem and check
    DB2_OVERRIDE_BPF registry when creating bufferpools during crash
    recovery or roll forward. This problem only occurs in 64 bit
    instance.
    Problem Summary:
    This problem is caused by a misoperation, when you create or alt
    er a bufferpool, the size is too large to allocated from OS and
    cause overrall performance of the system is very slow and seems
    hang. Another problem is that DB2_OVERRIDE_BPF registry only app
    lies to bufferpools that already exists, and not bufferpools wil
    l be created in crash recovery or roll forward. So DB2 will try
    to create this big bufferpool again when doing crash recovery or
     roll forward. We will fix this problem and check DB2_OVERRIDE_B
    PF registry in our crash recovery and roll forward code.
    
    		

    Problem conclusion

    				
    				
    		

    Temporary fix

    				You can use db2iupdt -w 32 <INSTNAME> to update the instance to
    a 32 bit instance, then you can connect to the database
    succefully. After that, use db2iupdt -w 64 <INSTNAME> to update
    the instance to 64 bit again. Please take a backup at this
    point, so we don't have to roll forward through bufferpool
    creation that fails if we need restore and roll
    forward database.Please also notice that be careful when creati
    ng bufferpool, don't specify a too large value.
    
    		


    posted @ 2007-03-15 15:21 MyJavaWorld 閱讀(740) | 評論 (0)編輯 收藏

    Change db2 password in db2 level

    DB2 depends on operation system level authorization to control DB2 system access.

    In some case, our db2 account only allows to connect to instance or database, but not log on the system. In other words, we are not able to use the account to get a shell on unix or logon locally on windows.

    As usual, when we need to change db2 password, we take action on the system level because it's more frank. But in the case above that we can't get logon, we have to do it on db2 level. There are 2 ways.

    • Use the GUI tool DB2 Configuration Assistance
    • Use the command line tools DB2 CLP or CE

    Using DB2 Configuration Assistance

    Right click on a database name, then choose "Change password".

    CA tool interface

    Note: When more than one databases live in same system, we might share the same account in multi-database. Changing password for one of them will affect all databases in this system. In other words, we don't need to do the change on each database, we could choose any we have privileges on the system.

    Limitation: We are not able to change our password in the case of that we are only allowed to attach to the node but not connect to any database, or we don't get the catalog information for any database in the node.

    For this limitation, it works out with the 2nd way.?

    Using DB2 CLP and CE

    We could use CLP and CE to change password for databases and nodes that we connected or attached to.

    • Change by connecting to database
    C:\> db2 connect to SAMPLE user TEST using OLDPWD new NEWPWD confirm NEWPWD
    C:\> db2 connect to SAMPLE user TEST using OLDPWD change password
    • Change by attaching to node, this way works out for the limitation in Configuration Assistance
    C:\> db2 attach to NODE user TEST using OLDPWD new NEWPWD confirm NEWPWD
    C:\> db2 attach to NODE user TEST using OLDPWD change password


    alter table xxx VOLATILE

    valatile

    • a. 反復無常的,揮發性的

    VOLATILE CARDINALITY or NOT VOLATILE CARDINALITY
    Indicates to the optimizer whether or not the cardinality of table table-name can
    vary significantly at run time. Volatility applies to the number of rows in the
    table, not to the table itself. CARDINALITY is an optional keyword. The default
    is NOT VOLATILE.

    VOLATILE
    Specifies that the cardinality of table table-name can vary significantly at
    run time, from empty to large. To access the table, the optimizer will use
    an index scan (rather than a table scan, regardless of the statistics) if that
    index is index-only (all referenced columns are in the index), or that index
    is able to apply a predicate in the index scan. The list prefetch access method
    will not be used to access the table. If the table is a typed table, this option
    is only supported on the root table of the typed table hierarchy (SQLSTATE 428DR).

    NOT VOLATILE
    Specifies that the cardinality of table-name is not volatile.
    Access plans to this table will continue to be based on existing statistics and
    on the current optimization level.

    NOTE: The keyword could be specified within ALTER TABLE, but not CREATE TABLE.

    ?

    Difference between Local and System Database Directory

    DB2 automatically catalogs databases when they are created. It catalogs an entry
    for the database in the local database directory and another entry in the system
    database directory. If the database is created from a remote client (or a client which
    is executing from a different instance on the same machine), an entry is also made
    in the system database directory at the client instance.

    Databases on the same node as the database manager instance are cataloged as
    indirect entries. Databases on other nodes are cataloged as remote entries.

    List DBs in Local Database Directory

    $ db2 list db directory on /path_to_where_db_created?

    List DBs in System Database Directory

    $ db2 list db directory

    ?

    Illustration of standard tables

    Standard Tables Overview

    Query the status for one specified tablespace?

    As we know, we could issue following command to query status for all of tablespaces in current connected DB.

    $ db2 list tablespaces show detail > /tmp/ts.list

    Then find the status for the tablespaces we concerned.

    Is there's a way to query the status for one specified tablespace?

    My answer is No.?

    1. First, I don't find the related column defination in the table or view:
      • sysibm.systablespaces
      • syscat.tablespaces
    2. Second, I don't think DB2 stores the status flag within syscata tables. The reason is that once a tablespace comes into a special status, it will not be allowed changing any longer(this may also happen on a system catalog tablespace.) that will lead to a conflict on changing the tablespace status flag if stores it within system catalog tables.

    Illustration of the DMS table-space address map

    address map for DMS TS

    DB2 directories and files

    • http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/c0005420.htm

    Illustration of DB2 architechure and process

    overview for tuning

    Reference

    • http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/c0005418.htm?

    Tablespaces are put into backup pending after a load

    DB2 sets tablespace as Backup Pending state after loading data into a table in linear logging database(that is, logretain or userexit is on), whatever the load is successful or failed. the reason is that the load process will not write log file. from the begin time of loading to the end time of loading, there will be a blank segment in log file, and the rollforward recovery can Not jump over the blank segment to apply the later log file.

    so database needs a backup after loading to make sure db2 have recovery capicibility.

    it's able to use [COPY YES|NO]? or [NONRECOVERABLE] to prevent tablespace go into Backup Pending state. COPY YES will do the backup automatically after loading, and COPY NO and NONRECOVERABLE will give up this backup that means db2 will be not able to recover the database once an serious error occured.


    繼續閱讀 "Tablespaces are put into backup pending after a load" 的剩余內容

    Come pending when droping Procedures

    Problem Description?

    There's no any response for creating or droping any procedures in DB2. Seems it's pending there, without any error returned. This time UPDATE statement on tables could be issued successfully.

    Check Process

    Check OS disk available

    $ df -kl?

    Check database configure

    db2 => get db cfg |more?

    Check system catalog tablespace?

    db2 => list tablespaces show detail |more
    syscatspace 0x0000?

    Cause?

    It caused by issuing CREATE or DROP statement without COMMIT or ROLLBACK statement in CLP which is in non-Autocommit mode.

    Solution?

    After you issue a COMMIT or a ROLLBACK in the CLP or close it, the pending is gone.

    We must be very careful when we use client in non-Autocommit mode just like CLPs in this case.

    To check the Autocommit mode in CLP issues. Refer to:

    set COMMIT mode in db2 clp

    db2 => list command options

    -c 自動落實 OFF

    More?

    From this point, we could get more. Most of strange things like this(pending there and no error return) are caused by locking.

    In this case, it was only the opertation on procedures being pended, so track on this thread to suppose the syscat tables related with procedures are locked then find the what probably causes it.
    ?

    db2 can not create index on local view

    There's an object called index view since MS SQL Server 2000, it's an index which is created on an view which is based on a local table. it is attent to imporve the select performence on the view when this view is based on multi-table and has complex logic.

    I try to find a simular thing in DB2, but there's no the simular solution in DB2 v8.2 for now. Instead, I found another thing instested.

    DB2 allows creating index on the tables or views in remote data source, such as a database on another host or an XML data source. To be exactly, that's Not true Index, it's Index Specification. It requests that the tables in remote data source have created index in its own system. And it only repeat the index description in local system.

    										Local DB2 Env??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? Remote DB2 Env
    										

    Index Specification??? ->??? Nickname?? - - ->?? True Index??? ->??? Table

    See following example in DB2 info center.

    • CREATE INDEX statement
      http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0000919.htm?resultof=%22%63%72%65%61%74%65%22%20%22%63%72%65%61%74%22%20%22%69%6e%64%65%78%22%20%22%73%74%61%74%65%6d%65%6e%74%22%20

    Example 3:? The nickname EMPLOYEE references a data source table called CURRENT_EMP. After this nickname was created, an index was defined on CURRENT_EMP. The columns chosen for the index key were WORKDEBT and JOB. Create an index specificationindex. Through this specification, the optimizer will know that the index exists and what its key is. With this information, the optimizer can improve its strategy to access the table. that describes this

       CREATE UNIQUE INDEX JOB_BY_DEPT
    ON EMPLOYEE (WORKDEPT, JOB)
    SPECIFICATION ONLY

    Note: the Nickname is only allowed to be created on tables in local database and on much kind of objects at remote data source. It's not allowed to be created on views in local database.

    set COMMIT mode in db2 clp

    As default, DB2 CLP will do commit after you issue each DB2 statements or SQL automatically.

    If you want to change it instead of issuing COMMIT or ROLLBACK manually, do following.

    SQLLIB\BIN> db2
    db2 => list command options
    ??? -c?? ON
    db2 => update command options using c off
    db2 => list command options
    ??? -c?? OFF

    This change will only exists during this session. The setting will lose when you close this CLP and open CLP next time.

    following cmd will get the same result with above.

    SQLLIB\BIN> db2 list command options
    ??? -c??? ON
    SQLLIB\BIN> db2 +c
    db2 =>
    db2 => list command options
    ??? -c??? OFF
    db2 => quit
    SQLLIB\BIN> db2 list command options
    ??? -c??? ON

    There's also the way to keep the settings forever, do following.

    SQLLIB\BIN\> db2 list command options
    ??? -c?? ON
    SQLLIB\BIN\> db2set db2options=+c
    SQLLIB\BIN\> db2 list command options
    ??? -c?? OFF

    This change will take effection immediately even for others having been opened CLP windows. And will keep along.

    Use following cmd set it back to ON.?

    SQLLIB\BIN> db2set db2opptions=-c

    Reference

    表與索引的重命名 RENAME

    在DB2 中重命名表或者索引

    db2=> RENAME TABLE EMP TO EMPLOYEE
    db2=> RENAME TABLE ABC.EMP TO EMPLOYEE
    db2=> RENAME INDEX NEW-IND TO IND
    db2=> RENAME INDEX ABC.NEW-IND TO IND
    posted @ 2007-03-15 15:00 MyJavaWorld 閱讀(528) | 評論 (0)編輯 收藏
    三個UNIX文件時間ctime、mtime、atime
    ?????? 我曾經根據文件的狀態在指定時間內是否改變寫過一個WatchDog來對服務進行監控,其間曾被這三個時間搞混淆,所以覺得很有必要和大家分享我對這三個術語的理解。
    ????? ctime(change time)改變時間:是指文件狀態最后一次被改變的時間;
    ????? mtime(modification time)修改時間:是指文件內容最后一次被改變的時間;
    ????? atime(access time)訪問時間:是指文件最后一次被讀取的時間。
    ????? 前兩者的區別就在于文件狀態的改變既包括文件索引節點的改變,也包括文件內容的改變。也就是說如果你改變了文件內容,則同時更新了ctime和mtime,但是如果你只改變了文件索引節點則只是改變了ctime。atime只有在文件被讀取的時侯才會改變。它的改變與文件狀態以及文件內容的改變沒有直接的聯系。
    ???? 例如:echo “Hello World” >> myfile 則同時改變了ctime和mtime,atime不變;
    ???? chmod u+x myfile 則只改變了ctime,mtime和atime不變。
    ???? cat myfile,則只改變了atime,ctime和mtime不變
    ???? ps:以上操作均在redhat linux下驗證通過
    posted @ 2007-03-13 17:51 MyJavaWorld 閱讀(1174) | 評論 (0)編輯 收藏
    ?
    ?
    查看文章
    ?
    DB2/SQL命令大全
    2006-12-25 13:21

    連接數據庫:

    ??connect?to?[數據庫名]?user?[操作用戶名]?using?[密碼]?

    創建緩沖池(8K):

    ??create?bufferpool?ibmdefault8k?IMMEDIATE??SIZE?5000?PAGESIZE?8?K?;
    創建緩沖池(16K)(OA_DIVERTASKRECORD):
    ??create?bufferpool?ibmdefault16k?IMMEDIATE??SIZE?5000?PAGESIZE?16?K?;
    創建緩沖池(32K)(OA_TASK):
    ??create?bufferpool?ibmdefault32k?IMMEDIATE??SIZE?5000?PAGESIZE?32?K?;

    創建表空間:

    ??CREATE?TABLESPACE?exoatbs?IN?DATABASE?PARTITION?GROUP?IBMDEFAULTGROUP?PAGESIZE?8K?MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoacontainer')?EXTENTSIZE?32?PREFETCHSIZE?16??BUFFERPOOL?IBMDEFAULT8K??OVERHEAD?24.10?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    ??CREATE?TABLESPACE?exoatbs16k??IN?DATABASE?PARTITION?GROUP?IBMDEFAULTGROUP?PAGESIZE?16K?MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoacontainer16k'???)?EXTENTSIZE?32??PREFETCHSIZE?16??BUFFERPOOL?IBMDEFAULT16K??OVERHEAD?24.1?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    ??CREATE?TABLESPACE?exoatbs32k??IN?DATABASE?PARTITION?GROUP?IBMDEFAULTGROUP?PAGESIZE?32K?MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoacontainer32k'???)?EXTENTSIZE?32??PREFETCHSIZE?16??BUFFERPOOL?IBMDEFAULT32K??OVERHEAD?24.1?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    GRANT?USE?OF?TABLESPACE?exoatbs?TO?PUBLIC;
    GRANT?USE?OF?TABLESPACE?exoatbs16k?TO?PUBLIC;
    GRANT?USE?OF?TABLESPACE?exoatbs32k?TO?PUBLIC;

    創建系統表空間:

    ??CREATE?TEMPORARY?TABLESPACE?exoasystmp?IN?DATABASE?PARTITION?GROUP?IBMTEMPGROUP?PAGESIZE?8K??MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoasystmp'???)?EXTENTSIZE?32?PREFETCHSIZE?16?BUFFERPOOL?IBMDEFAULT8K??OVERHEAD?24.10?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    ??CREATE?TEMPORARY?TABLESPACE?exoasystmp16k?IN?DATABASE?PARTITION?GROUP?IBMTEMPGROUP?PAGESIZE?16K?MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoasystmp16k'??)?EXTENTSIZE?32?PREFETCHSIZE?16?BUFFERPOOL?IBMDEFAULT16K?OVERHEAD?24.10?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    ??CREATE?TEMPORARY?TABLESPACE?exoasystmp32k?IN?DATABASE?PARTITION?GROUP?IBMTEMPGROUP?PAGESIZE?32K?MANAGED?BY?SYSTEM?USING?('/home/exoa2/exoasystmp32k')?EXTENTSIZE?32?PREFETCHSIZE?16?BUFFERPOOL?IBMDEFAULT32K?OVERHEAD?24.10?TRANSFERRATE?0.90??DROPPED?TABLE?RECOVERY?OFF;

    1.?啟動實例(db2inst1):

    db2start

    2.?停止實例(db2inst1):

    db2stop

    3.?列出所有實例(db2inst1)

    db2ilist

    5.列出當前實例:

    db2?get?instance

    4.?察看示例配置文件:

    db2?get?dbm?cfg|more

    5.?更新數據庫管理器參數信息:

    db2?update?dbm?cfg?using?para_name?para_value

    6.?創建數據庫:

    db2?create?db?test

    7.?察看數據庫配置參數信息

    db2?get?db?cfg?for?test|more

    8.?更新數據庫參數配置信息

    db2?update?db?cfg?for?test?using?para_name?para_value

    10.刪除數據庫:

    db2?drop?db?test

    11.連接數據庫

    db2?connect?to?test

    12.列出所有表空間的詳細信息。

    db2?list?tablespaces?show?detail

    13.查詢數據:

    db2?select?*?from?tb1

    14.刪除數據:

    db2?delete?from?tb1?where?id=1

    15.創建索引:

    db2?create?index?idx1?on?tb1(id);

    16.創建視圖:

    db2?create?view?view1?as?select?id?from?tb1

    17.查詢視圖:

    db2?select?*?from?view1

    18.節點編目

    db2?catalog?tcp?node?node_name?remote?server_ip?server?server_port

    19.察看端口號

    db2?get?dbm?cfg|grep?SVCENAME

    20.測試節點的附接

    db2?attach?to?node_name

    21.察看本地節點

    db2?list?node?direcotry

    22.節點反編目

    db2?uncatalog?node?node_name

    23.數據庫編目

    db2?catalog?db?db_name?as?db_alias?at?node?node_name

    24.察看數據庫的編目

    db2?list?db?directory

    25.連接數據庫

    db2?connect?to?db_alias?user?user_name?using?user_password

    26.數據庫反編目

    db2?uncatalog?db?db_alias

    27.導出數據

    db2?export?to?myfile?of?ixf?messages?msg?select?*?from?tb1

    28.導入數據

    db2?import?from?myfile?of?ixf?messages?msg?replace?into?tb1

    29.導出數據庫的所有表數據

    db2move?test?export

    30.生成數據庫的定義

    db2look?-d?db_alias?-a?-e?-m?-l?-x?-f?-o?db2look.sql

    31.創建數據庫

    db2?create?db?test1

    32.生成定義

    db2?-tvf?db2look.sql

    33.導入數據庫所有的數據

    db2move?db_alias?import

    34.重組檢查

    db2?reorgchk

    35.重組表tb1

    db2?reorg?table?tb1

    36.更新統計信息

    db2?runstats?on?table?tb1

    37.備份數據庫test

    db2?backup?db?test

    38.恢復數據庫test

    db2?restore?db?test

    399\.列出容器的信息

    db2?list?tablespace?containers?for?tbs_id?show?detail

    40.創建表:

    db2?ceate?table?tb1(id?integer?not?null,name?char(10))

    41.列出所有表

    db2?list?tables

    42.插入數據:

    db2?insert?into?tb1?values(1,’sam’);

    db2?insert?into?tb2?values(2,’smitty’);

    .?建立數據庫DB2_GCB?

    CREATE?DATABASE?DB2_GCB?ON?G:?ALIAS?DB2_GCB?

    USING?CODESET?GBK?TERRITORY?CN?COLLATE?USING?SYSTEM?DFT_EXTENT_SZ?32?

    2.?連接數據庫?

    connect?to?sample1?user?db2admin?using?8301206?

    3.?建立別名?

    create?alias?db2admin.tables?for?sysstat.tables;?

    CREATE?ALIAS?DB2ADMIN.VIEWS?FOR?SYSCAT.VIEWS?

    create?alias?db2admin.columns?for?syscat.columns;?

    create?alias?guest.columns?for?syscat.columns;?

    4.?建立表?

    create?table?zjt_tables?as?

    (select?*?from?tables)?definition?only;?

    create?table?zjt_views?as?

    (select?*?from?views)?definition?only;?

    5.?插入記錄?

    insert?into?zjt_tables?select?*?from?tables;?

    insert?into?zjt_views?select?*?from?views;?

    6.?建立視圖?

    create?view?V_zjt_tables?as?select?tabschema,tabname?from?zjt_tables;?

    7.?建立觸發器?

    CREATE?TRIGGER?zjt_tables_del?

    AFTER?DELETE?ON?zjt_tables?

    REFERENCING?OLD?AS?O?

    FOR?EACH?ROW?MODE?DB2SQL?

    Insert?into?zjt_tables1?values(substr(o.tabschema,1,8),substr(o.tabname,1,10))?

    8.?建立唯一性索引?

    CREATE?UNIQUE?INDEX?I_ztables_tabname?

    [size=3]ON?zjt_tables(tabname);?

    9.?查看表?

    select?tabname?from?tables?

    where?tabname='ZJT_TABLES';?

    10.?查看列?

    select?SUBSTR(COLNAME,1,20)?as?列名,TYPENAME?as?類型,LENGTH?as?長度?

    from?columns?

    where?tabname='ZJT_TABLES';?

    11.?查看表結構?

    db2?describe?table?user1.department?

    db2?describe?select?*?from?user.tables?

    12.?查看表的索引?

    db2?describe?indexes?for?table?user1.department?

    13.?查看視圖?

    select?viewname?from?views?

    where?viewname='V_ZJT_TABLES';?

    14.?查看索引?

    select?indname?from?indexes?

    where?indname='I_ZTABLES_TABNAME';?

    15.?查看存貯過程?

    SELECT?SUBSTR(PROCSCHEMA,1,15),SUBSTR(PROCNAME,1,15)?

    FROM?SYSCAT.PROCEDURES;?

    16.?類型轉換(cast)?

    ip?datatype:varchar?

    select?cast(ip?as?integer)+50?from?log_comm_failed?

    17.?重新連接?

    connect?reset?

    18.?中斷數據庫連接?

    disconnect?db2_gcb?

    19.?view?application?

    LIST?APPLICATION;?

    20.?kill?application?

    FORCE?APPLICATION(0);?

    db2?force?applications?all?(強迫所有應用程序從數據庫斷開)?

    21.?lock?table

    lock?table?test?in?exclusive?mode?

    22.?共享?

    lock?table?test?in?share?mode?

    23.?顯示當前用戶所有表?

    list?tables?

    24.?列出所有的系統表?

    list?tables?for?system?

    25.?顯示當前活動數據庫?

    list?active?databases?

    26.?查看命令選項?

    list?command?options?

    27.?系統數據庫目錄?

    LIST?DATABASE?DIRECTORY?

    28.?表空間?

    list?tablespaces?

    29.?表空間容器?

    LIST?TABLESPACE?CONTAINERS?FOR?

    Example:?LIST?TABLESPACE?CONTAINERS?FOR?1?

    30.?顯示用戶數據庫的存取權限?

    GET?AUTHORIZATIONS?

    31.?啟動實例?

    DB2START?

    32.?停止實例?

    db2stop?

    33.?表或視圖特權?

    grant?select,delete,insert,update?on?tables?to?user?

    grant?all?on?tables?to?user?WITH?GRANT?OPTION?

    34.?程序包特權?

    GRANT?EXECUTE?

    ON?PACKAGE?PACKAGE-name?

    TO?PUBLIC?

    35.?模式特權?

    GRANT?CREATEIN?ON?SCHEMA?SCHEMA-name?TO?USER?

    36.?數據庫特權?

    grant?connect,createtab,dbadm?on?database?to?user?

    37.?索引特權?

    grant?control?on?index?index-name?to?user?

    38.?信息幫助?(??XXXnnnnn?)?

    例:??SQL30081?

    39.?SQL?幫助(說明?SQL?語句的語法)?

    help?statement?

    例如,help?SELECT?

    40.?SQLSTATE?幫助(說明?SQL?的狀態和類別代碼)?

    ??sqlstate?或???class-code?

    41.?更改與"管理服務器"相關的口令?

    db2admin?setid?username?password?

    42.?創建?SAMPLE?數據庫?

    db2sampl?

    db2sampl?F:(指定安裝盤)?

    43.?使用操作系統命令?

    !?dir?

    44.?轉換數據類型?(cast)?

    SELECT?EMPNO,?CAST(RESUME?AS?VARCHAR(370))?

    FROM?EMP_RESUME?

    WHERE?RESUME_FORMAT?=?'ascii'?

    45.?UDF

    要運行?DB2?Java?存儲過程或?UDF,還需要更新服務器上的?DB2?數據庫管理程序配置,以包括在該機器上安裝?JDK?的路徑?

    db2?update?dbm?cfg?using?JDK11_PATH?d:sqllibjavajdk?

    TERMINATE?

    update?dbm?cfg?using?SPM_NAME?sample?

    46.?檢查?DB2?數據庫管理程序配置?

    db2?get?dbm?cfg?

    47.?檢索具有特權的所有授權名?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'DATABASE'?FROM?SYSCAT.DBAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'TABLE?'?FROM?SYSCAT.TABAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'PACKAGE?'?FROM?SYSCAT.PACKAGEAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'INDEX?'?FROM?SYSCAT.INDEXAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'COLUMN?'?FROM?SYSCAT.COLAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'SCHEMA?'?FROM?SYSCAT.SCHEMAAUTH?

    UNION?

    SELECT?DISTINCT?GRANTEE,?GRANTEETYPE,?'SERVER?'?FROM?SYSCAT.PASSTHRUAUTH?

    ORDER?BY?GRANTEE,?GRANTEETYPE,?3?

    create?table?yhdab?

    (id?varchar(10),?

    password?varchar(10),?

    ywlx?varchar(10),?

    kh?varchar(10));?

    create?table?ywlbb?

    (ywlbbh?varchar(8),?

    ywmc?varchar(60))?

    48.?修改表結構?

    alter?table?yhdab?ALTER?kh?SET?DATA?TYPE?varchar(13);?

    alter?table?yhdab?ALTER?ID?SET?DATA?TYPE?varchar(13);?

    alter?table?lst_bsi?alter?bsi_money?set?data?type?int;?

    insert?into?yhdab?values?

    ('20000300001','123456','user01','20000300001'),?

    ('20000300002','123456','user02','20000300002');?

    49.?業務類型說明?

    insert?into?ywlbb?values?

    ('user01','業務申請'),?

    ('user02','業務撤消'),?

    ('user03','費用查詢'),?

    ('user04','費用自繳'),?

    ('user05','費用預存'),?

    ('user06','密碼修改'),?

    ('user07','發票打印'),?

    ('gl01','改用戶基本信息'),?

    ('gl02','更改支付信息'),?

    ('gl03','日統計功能'),?

    ('gl04','沖帳功能'),?

    ('gl05','對帳功能'),?

    ('gl06','計費功能'),?

    ('gl07','綜合統計')?

    備份數據庫:
    CONNECT?TO?EXOA;
    QUIESCE?DATABASE?IMMEDIATE?FORCE?CONNECTIONS;
    CONNECT?RESET;
    BACKUP?DATABASE?EXOA?TO?"/home/exoa2/db2bak/"?WITH?2?BUFFERS?BUFFER?1024?PARALLELISM?1?WITHOUT?PROMPTING;
    CONNECT?TO?EXOA;
    UNQUIESCE?DATABASE;
    CONNECT?RESET;

    以下是小弟在使用db2move中的一些經驗,希望對大家有所幫助。?

    ?db2???connect???to??YOURDB???
    連接數據庫?

    ?db2look?-d??YOURDB??-a?-e?-x?-o?creatab.sql?
    導出建庫表的SQL?

    ?db2move???YOURDB??export?
    用db2move將數據備份出來?

    ?vi???creatab.sql?
    如要導入的數據庫名與原數據庫不同,要修改creatab.sql中CONNECT?項?
    如相同則不用更改?

    ?db2move??NEWDB??load?
    將數據導入新庫中?

    在導入中可能因為種種原因發生中斷,會使數據庫暫掛?
    db2????list?tablespaces???show???detail?
    如:?
    ??????詳細說明:?
    ?????裝入暫掛?
    ?總頁數??????????????????????????=?1652?
    ?可用頁數????????????????????????=?1652?
    ?已用頁數?????????????????????????=?1652?
    ?空閑頁數?????????????????????????=?不適用?
    ?高水位標記(頁)?????????????????=?不適用?
    ?頁大小(字節)???????????????????=?4096?
    ?盤區大小(頁)???????????????????=?32?
    ?預讀取大小(頁)?????????????????=?32?
    ?容器數???????????????????????????=?1?
    ?狀態更改表空間標識????????????????????=?2?
    ?狀態更改對象標識??????????????????????=?59?

    ?db2?select?tabname,tableid?from?syscat.tables?where?tableid=59?
    查看是哪張表掛起?

    表名知道后到db2move.lst(在db2move??YOURDB??export的目錄中)中找到相應的.ixf文件?
    ?db2?load?from?tab11.ixf?of?ixf?terminate?into?db2admin.xxxxxxxxx?
    tab11.ixf對應的是xxxxxxxxx表?

    數據庫會恢復正常,可再用db2?list?tablespaces?show?detail查看

    30.不能通過GRANT授權的權限有哪種?

    SYSAM

    SYSCTRL

    SYSMAINT

    要更該述權限必須修改數據庫管理器配置參數

    31.表的類型有哪些?

    永久表(基表)

    臨時表(說明表)

    臨時表(派生表)

    32.如何知道一個用戶有多少表?

    SELECT*FROMSYSIBM.SYSTABLESWHERECREATOR='USER'

    33.如何知道用戶下的函數?

    select*fromIWH.USERFUNCTION

    select*fromsysibm.SYSFUNCTIONS

    34.如何知道用戶下的VIEW數?

    select*fromsysibm.sysviewsWHERECREATOR='USER'

    35.如何知道當前DB2的版本?

    select*fromsysibm.sysvERSIONS

    36.如何知道用戶下的TRIGGER數?

    select*fromsysibm.SYSTRIGGERSWHERESCHEMA='USER'

    37.如何知道TABLESPACE的狀況?

    select*fromsysibm.SYSTABLESPACES

    38.如何知道SEQUENCE的狀況?

    select*fromsysibm.SYSSEQUENCES

    39.如何知道SCHEMA的狀況?

    select*fromsysibm.SYSSCHEMATA

    40.如何知道INDEX的狀況?

    select*fromsysibm.SYSINDEXES

    41.如何知道表的字段的狀況?

    select*fromsysibm.SYSCOLUMNSWHERETBNAME='AAAA'

    42.如何知道DB2的數據類型?

    select*fromsysibm.SYSDATATYPES

    43.如何知道BUFFERPOOLS狀況?

    select*fromsysibm.SYSBUFFERPOOLS

    44.DB2表的字段的修改限制?

    只能修改VARCHAR2類型的并且只能增加不能減少.

    45.如何查看表的結構?

    DESCRIBLETABLETABLE_NAME

    OR

    DESCRIBLESELECT*FROMSCHEMA.TABLE_NAME

    ?
    ?

    ? ? ?
    ?
    posted @ 2006-12-28 16:57 MyJavaWorld 閱讀(2762) | 評論 (0)編輯 收藏

    DB2 UDB中用戶出口程序是如何工作的?

    ?

    采用用戶出口程序與DB2 UDB共同工作背后的基本思想是提供一種歸檔和檢索數據庫日志文件的方法以實現日志冗余處理并從易失性介質上轉儲出來。重要的,值得注意的是,根據你的特殊需求,在用戶出口程序當中,除了能實現歸檔和檢索日志之外,你還可以實現其他的操作。

    ?

    如果一個數據庫需要采用歸檔日志文件來進行恢復,在DB2 UDB中實行用戶出口程序策略將不能恢復100%的事務。用戶出口程序只是一種通過拷貝已經存在的日志文件到一個安全的地方來為其提供更多保護的方法。它是數據完整性策略中的一部分,而且是重要的一部分。

    ?

    編譯了用戶出口程序之后,可執行程序db2uext2被放置在數據庫管理器可以找到的目錄當中。在UNIX?中,這個目錄是/sqllib/adm;在Windows?中,是Program FilesIBMSQLLIBBIN。

    ?

    除非數據庫管理器知道用戶出口程序是可用的,不然它不會調用db2uext2。讓數據庫管理器知道db2uext2可以被調用的唯一方法是將數據庫配置參數userexit設置為on。一旦這個參數被設定好而且DB2實例被重復利用了,數據庫管理器將每五分鐘調用一次用戶出口程序來檢查那些可以被歸檔到程序相關的歸檔目錄的日志文件。

    ?

    如果數據庫的恢復是必要的,在前滾操作期間,數據庫管理器將調用db2uext2把歸檔日志文件拷貝回活動的日志目錄當中。然后,日志文件被再次運用到重建的數據庫中。

    ?

    讓我們看看被數據庫管理器生成的到用戶出口程序的調用的格式。注意,這一信息也可以在用戶出口示例程序的注釋部分找到。

    db2uext2 -OS -RL

    -RQ -DB -NN

    -LP -LN [-AP]

    ?

    其中:

    os=操作系統

    release=DB2發行版本

    request= 'ARCHIVE' 或 'RETRIEVE'

    dbname=數據庫名

    nodenumber=節點號

    logpath=日志文件目錄

    logname=日志文件名

    logsize=日志文件大小(可選)

    startingpage=以4k頁為單位的起始偏移量(可選)

    adsmpasswd=ADSM密碼(可選)

    ?

    注意:只有當logpath為裸設備時才使用logsize和startingpage。

    ?

    歸檔或者從磁盤檢索日志文件遵從以下命名規則:

    歸檔:歸檔路徑+數據庫名+節點號+日志文件名

    檢索:檢索路徑+數據庫名+節點號+日志文件名

    ?

    比如:如果歸檔的路徑為”c:mylogs”,

    檢索路徑是“c:mylogs”,

    數據庫名是“SAMPLE”,

    節點號是 NODE0000,

    文件名是 S0000001.LOG,

    日志文件將是:

    歸檔到 - c:mylogsSAMPLENODE0000S0000001.LOG

    檢索自 - c:mylogsSAMPLENODE0000S0000001.LOG

    以下描述了用戶出口程序中的邏輯是如何運轉的:

    1)? 安裝信號處理程序。

    2)? 驗證傳遞的參數個數。

    3)? 驗證操作請求。

    4)? 開始審計跟蹤(如果有此請求)。

    5)? 根據操作需求的不同獲取以下路徑中的一個:

    a)? 如果操作需求為歸檔一個文件,將日志文件從日志路徑拷貝到歸檔路徑中。

    i) 如果沒有找到日志文件,執行第6點。

    ?

    b)? 如果操作需求是檢索一個文件,將日志文件從檢索路徑拷貝到日志路徑中。

    i) 如果沒有找到日志文件,執行第6點。

    6) 將錯誤記入日志(如果要求或者有需要的話)。

    7)? 結束審計跟蹤(如果有請求)。

    8)? 以適當的返回碼退出。

    ?

    手工調用用戶出口程序來歸檔日志文件是可以的,但最好還是使用ARCHIVE LOG命令以便在定義以上參數時不會因為你的原因導致錯誤。在這篇文章的末尾,可以找到關于ARCHIVE LOG命令的鏈接。

    ?

    日志文件術語

    ?

    DB2 中用戶出口程序的基本功能是將日志文件拷貝到活動日志目錄或反之。這里,值得指出一些術語來闡明活動的日志目錄被置于何處以及數據庫日志文件的狀態如何。

    ?

    活動日志目錄:

    ?

    該目錄被置于你的數據庫目錄中。在Windows中,如果在C:中創建了一個叫做SAMPLE的單一數據庫且實例名為db2inst1,則將會出現以下的目錄結構:

    ?

    C:DB2INST1NODE0000SQL000001SQLOGDIR

    ?

    SQL00001是SAMPLE數據庫的數據庫目錄,SQLOGDIR 是活動日志目錄。

    ?

    以下的圖1顯示了Windows操作系統上的活動日志目錄:

    PATH o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" />SHAPE id=_x0000_i1025 style="WIDTH: 299.25pt; HEIGHT: 180.75pt" type="#_x0000_t75" />/P>

    ?

    圖 1活動日志目錄

    日志文件狀態

    ?

    在活動日志目錄中,日志文件可以是活動日志,也可以是聯機歸檔日志。活動日志是那些被 DB2 用于當前事務處理和崩潰恢復的日志。聯機歸檔日志是那些 DB2 UDB 進行常規處理時不再需要,而進行數據庫恢復時可能還會需要的日志。當實現用戶出口程序時,這些聯機歸檔日志將最終以歸檔日志目錄中的副本形式出現。

    ?

    既然 DB2 UDB 中用戶出口程序的目的是將數據庫日志拷貝到歸檔目錄中,你將最終在活動日志目錄(缺省為 SQLOGDIR)中得到重復的日志文件。你可能考慮刪除這些重復的聯機歸檔日志以釋放文件系統空間。在從數據庫目錄中除去這些日志之前,要十分小心地確認它們是否已經將成功地被復制到歸檔目錄中。還必須確保數據庫管理器進行崩潰恢復時不再需要它們。要確定你的活動日志目錄中哪些日志文件不為正常處理所需要,可用通過以下命令檢查數據庫配置:

    ????????

    ???? db2 "get db cfg for sample"

    ?

    這條命令的數據庫配置輸出結果將包含第一個活動日志文件,如:

    First active log file = S000009.LOG

    ?

    在如上所示的輸出當中,日志文件S000009.LOG是數據庫當前的活動日志。任何編號比該日志文件小的日志文件都被看作聯機歸檔日志。

    ?

    這里有一個例子:

    ?

    在這個場景中,活動日志目錄中有日志文件 S000000.LOG - S000009.LOG,歸檔日志目錄中有 S000000.LOG - S000008.LOG。因為 S000009.LOG 是第一個活動日志文件,所以,可以從活動日志目錄中移走 S000001.LOG - S000008.LOG 以釋放磁盤空間。S000009.LOG 文件必須保留在活動日志目錄中,因為它仍然被當前事務使用。

    ?

    同樣可以通過檢查數據庫歷史文件來查看活動日志目錄中哪些日志文件不再有用。以下命令將列出數據庫備份信息:

    ?

    ???? db2 "list history backup all for database sample"

    ?

    以下是該命令的輸出結果的一個例子:

    ?

    List History File for sample

    Number of matching file entries = 4

    Op Obj Timestamp+Sequence Type Dev Earliest Log Current? Log

    -- --- ------------------ ---- --- ------------------------

    B D 20030416162026001 F D S0000010.LOGS0000014.LOG

    ------------------------------------------------------------

    Contains 2 tablespace(s):

    00001 SYSCATSPACE

    00002 USERSPACE1

    ------------------------------------------------------------

    ?

    在上面的輸出中,最早的日志將表示,需要 S0000010.LOG 及其之后的任何日志。 S00000010.LOG 之前的任何日志可以被安全的刪除。再次提醒,在從活動日志目錄中刪除日志文件之前,驗證在活動日志目錄中存在這些日志文件的拷貝是十分重要的。

    ?

    雖然可以手動的從活動日志目錄中刪除日志文件,刪除聯機歸檔日志文件的安全方法是通過prune logfile命令。該命令可以用來刪除活動歸檔目錄中的日志文件。在下面的示例中,以下命令將刪除日志文件 S000000.LOG - S000008.LOG:

    ???? db2 "prune logfile prior to S000009.LOG"

    ?

    注意:根據您的恢復策略,可能會出現之前的前滾操作在數據庫上執行的場景。歸檔目錄中的老日志文件可能被同名的新日志文件所覆蓋,從而阻止你使用舊日志文件對數據庫進行時間點恢復。對用戶出口程序的設計程序員來說,考慮類似這樣的情況是很重要的。

    ?

    設置用戶出口

    ?

    在本文中,我們將采用DB2提供的db2uext2.cdisk樣例c程序,它位于你的c目錄當中。在UNIX中,c目錄位于/sqllib/samples。Windows中,這目錄位于Program Files/IBM//samples。

    ?

    在Windows中設置用戶出口

    ?

    修改和編譯用戶出口程序

    1.? 創建名為C:mylogs的目錄

    2.? 將C:Program filesIBMSQLLIBsamplescdb2uext2.cdisk拷貝到一個工作目錄當中

    3.? 對于本示例,用戶出口程序的以下部分應該得以驗證以反映路徑 c:\mylogs\

    ?

    #define ARCHIVE_PATH "c:\mylogs\"

    #define RETRIEVE_PATH "c:\mylogs\"

    #define AUDIT_ACTIVE 1 /* enable audit trail logging */

    #define ERROR_ACTIVE 1 /* enable error trail logging */

    #define AUDIT_ERROR_PATH "c:\mylogs\"

    ???????????????? /* path must end with a slash */

    #define AUDIT_ERROR_ATTR "a" /* append to text file */

    #define BUFFER_SIZE 32

    ??? /* # of 4K pages for output buffer */

    ?

    4.? 確定在你的系統中安裝了被支持的C編譯器(比如,Microsoft Visual Studio)而且環境中有該編譯器的路徑。

    5.? 通過命令行,將db2uext2.cdisk更名為db2uext2.c并構建:

    cl db2uext2.c

    一旦程序被編譯,將創建db2uext2.exe和db2uext2.obj文件。

    6.? 將可執行文件db2uext2.exe放到/SQLLIB/BIN目錄當中從而使數據庫管理器能夠定位并執行它用以歸檔和檢索日志。

    ?

    為用戶出口創建并準備數據庫

    7.? 在 DB2 命令窗口中用 db2sampl 命令創建 SAMPLE 數據庫。這將使你對下面的示例使用樣本表。

    db2sampl

    8.? 更新數據庫配置文件以便為數據庫打開用戶出口。請注意:只能為一個數據庫分配用戶出口程序,因為 bin 目錄被所有 DB2 實例共享。

    db2 "update db cfg for sample using userexit on"

    db2stop force

    <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋體; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋體; mso-

    /P>
    posted @ 2006-12-08 18:12 MyJavaWorld 閱讀(418) | 評論 (0)編輯 收藏
    其實主要的就是要創建一個密鑰倉庫以管理您的公鑰 / 私鑰對來自您所信任實體的證書。
    ?
    第一步:生成密鑰對
    您首先要做的是創建一個密鑰倉庫和生成密鑰對。您可以使用以下命令: ?
    keytool -genkey -keyalg RSA -keysize 512 -dname "cn=hyq,o=eagle,c=cn" -alias weblogic -keypass 123456 -keystore C:/mykeystore/weblogic.jks -storepass 123456 -validity 365

    (請注意:鍵入該命令時必須使其成為一行。此處用多行來顯示,主要是為了可讀性。)如下圖:
    Snap2.gif

    該命令將在 ?C? 盤的 “mykeystore” 目錄中創建名為 “weblogic.jks” 的密鑰倉庫,并賦予它口令 123456 。它將為實體生成公鑰 / 私鑰對,該實體的 特征名 為:常用名 “hyq” 、組織 “eagle” 和兩個字母的國家代碼 “cn” 。“ -keyalg ”指定它使用的是那種密鑰生成算法來創建密鑰,缺省的是 “DSA” 密鑰生成算法(會使用缺省的 ?DSA? ?SHA1” 簽名算法),兩個密鑰(公鑰與私鑰)的長度是 512 位,由 -keysize 來指定,默認的是 1024? 位。 ? 該證書包括公鑰和特征名信息。該證書的有效期為 365 天,由 -validity 來指定,且與別名 “business” 所代表的密鑰倉庫項關聯。私鑰被賦予口令 123456

    ?

    命令行里 DName 信息注解

    ?

    DN 信息域

    含義

    CN

    域名或 IP

    OU

    部門,沒有部門的可不要此項

    O

    單位名稱

    L

    單位地址

    S

    省份的拼音(第一個字母大寫)

    C

    國家的簡寫 ( CN 代表中國)


    如果采用選項的缺省值,可以大大縮短該命令。實際上,這些選項并不是必需的;對于有缺省值的選項,未指定時將使用缺省值,對于任何被要求的值,您將會得到要求輸入它的提示。例如:輸入命令 keytool -genkey -keystore "C:/tone.jks" -storepass 123456 -keyalg RSA ,就會有如下提示:
    Snap3.gif


    注意:這里的
    密鑰倉庫路徑一定要存在,如果不存在的話,它就會拋如下的異常

    Snap4.gif
    第二步
    : 產生證書請求certreq.pem 文件

    使用如下命令:

    keytool -certreq -alias weblogic -sigalg "MD5withRSA" -file C:/mykeystore/certreq.pem -keypass 123456 -keystore C:/mykeystore/weblogic.jks -storepass 123456

    Snap5.gif
    這樣在
    C:/mykeystore/ 目錄下 就會產生一個 certreq.pem 文件,內容如下:

    -----BEGIN NEW CERTIFICATE REQUEST-----

    MIHlMIGQAgEAMCsxCzAJBgNVBAYTAmNuMQ4wDAYDVQQKEwVlYWdsZTEMMAoGA1UEAxMDaHlxMFww

    DQYJKoZIhvcNAQEBBQADSwAwSAJBAMhaIG2Ki7+RwZUP4gPBdTbnY38bisW16u1XUyysPxdNwSie

    aSd6E3Hm277E7NjHoz56ZoaYdPPDmdiTkMrS9rcCAwEAAaAAMA0GCSqGSIb3DQEBBAUAA0EAYRNl

    l5dyGgV9hhu++ypcJNQTrDIwjx1QT4fgVubrtIaHU0fzHamD5QG6PYddw9TL51XQHvu6tOS0NUc/

    ItNKJw==

    -----END NEW CERTIFICATE REQUEST-----

    第三步:這就相對來說簡單多了,就是CA提交證書請求。
    ??? 你可以隨便從網上找一家免費的CA認證適用機構(很多的),然后按照上面的提示進行操作就可以了,這一步就要用到前面生成的certreq.pem 文件了。(注意:一定要下載根證書)
    ??? 將生成的證書和下載的根證書放至你比較容易找到的位置,我一般將它們和生成的jks文件放到一起。

    第四步:導入證書
    ??? 通過命令:keytool -import -alias RootCA -trustcacerts -file C:/mykeystore/RootCADemo.cer -keystore C:/mykeystore/weblogic.jks -storepass 123456將根證書導入第一步生成的weblogic.jks中,接著將所有其它的證書按照此命令全部導入。(注意證書的別名不能重復,同時一定注意要用上 -trustcacerts,否則,你在以后使用時,它將會認為你導入的這些證書是不可信任的 ,就會導致你在配置SSL時不能正常的工作。)
    ??? 這就全部完成了密鑰倉庫的創建。然后就可以在支持這些證書格式的服務器上使用了。下一篇將會寫一下在weblogic上如何配置雙向SSL

    posted @ 2006-10-31 17:18 MyJavaWorld 閱讀(454) | 評論 (0)編輯 收藏
    現在的DB2 UDB系統中, 主要通過鎖和隔離級別這兩個主要的工具來控制并發連接,維護數據庫中的數據在高并發的環境下的安全。

    我們在這里將簡要的闡述一下鎖和隔離級別。

    鎖:

    DB2 UDB中, 鎖的主要作用對象是表和行, 其他如表空間和索引也是鎖的對象, 但是因為其多為系統控制, 管理員和用戶使用較少,在這里就不涉及了。

    對于行級鎖和表級鎖, 它們的區別不言而喻, 主要是鎖的對象不同。 當然鎖對象的不同連帶也會影響DB2的并發能力。

    DB2中的表級鎖主要有以下幾種:

    1. IS鎖: 此鎖作用于整個表,表示擁有此鎖的應用連接要讀取表中的某些數據, 但是在此應用連接讀取具體的數據時, 還必須獲得該行的行級鎖;

    2. IX鎖: 此鎖作用于整個表,表示擁有此鎖的應用連接需要獨占使用表中的某些數據, 但是在此應用連接獨占使用具體的數據時, 還必須獲得該行上相應的行級鎖;

    3. SIX鎖: 此鎖是鎖轉換的產物,表示應用連接擁有S和IX鎖的特性;

    4. S鎖: 此鎖作用于整個表, 擁有此鎖的應用連接可以讀取表中的任何紀錄;

    5. U鎖: 此鎖作用于整個表, 擁有此鎖的應用連接可以讀取表中的任何紀錄,也可以更新表中的紀錄, 但是更新時需要再獲得X鎖; 此鎖主要在“select … with update”語句建立的可更新游標中起作用, 其他的應用可以讀取表中的紀錄, 但是不能更新它;

    6. X鎖: 此鎖作用于整個表, 擁有此鎖的應用連接獨占的使用表中的任何紀錄;可以進行更新或其他操作;

    7. Z鎖: 此鎖作用于整個表, 也稱超級獨占鎖,主要是在象修改表的定義、 刪除表這一類的語句中會使用。 擁有此鎖的應用連接對該表有完全的控制權。 其他的任何應用不能讀取或更新表中的任何紀錄。

    在這里我們主要要看一下 IS/IX/SIX這三個鎖。 在這三個鎖中IS/IX本身并不具備使得應用連接可以讀取或更新紀錄的能力,應用連接要讀取和更新紀錄時, 需要再得到相應的行級鎖; 反之亦然, 任何應用要獲得行級鎖操作數據記錄之前, 也必須獲得某個相應的表級鎖。 SIX鎖也是類似的情況。這就是為什麼在很多情況下我們使用的是行級鎖, 但是用快照(SNAPSHOT)等工具卻能夠看到有表級鎖存在的原因。

    那麼DB2中又有哪些行級鎖呢? 讓我們來看下面的這張圖:

    那麼DB2中又有哪些行級鎖呢?

    此圖中列出了DB2中包含的行級鎖。 表中的第三列指出, 要獲得此行級鎖之前, 需要預先獲得的表級鎖, 這里列出的是最低要求。

    這六個行級鎖的主要功能如下:

    1. S鎖:此行級鎖的擁有者可以讀取該行的信息;

    2. U鎖:此行級鎖的擁有者可以讀取該行的信息,如果要更新該行,則仍然需要一個行級的X鎖;其他的應用只能讀取該行的信息;此鎖主要是用于FOR UPDATE的游標。

    3. X鎖:此行級鎖的擁有者可以更新該行的紀錄,其他的應用不能連接此行的信息;

    4. W鎖:此鎖和X鎖類似,不同之處是此鎖和NW鎖兼容;

    5. NS鎖:類似于S鎖,用于Next Key;

    6. NW鎖:類似于W鎖,用于Next Key;

    在DB2數據庫中, 是通過行級鎖和表級鎖協調作用來提供較好的并發性, 同時保證數據庫中數據的安全。 在DB2中缺省情況下使用行級鎖(當然需要IS/IX鎖配合),只有當出現鎖資源不足, 或者是用命令指定使用表級鎖的情況下, 才會在應用連接中使用表級鎖。 對鎖資源分配有興趣的讀者可以參考DB2的管理手冊, 查找其中關于locklist和maxlocks參數的論述。對于用命令指定表級鎖的情況, 可以參考DB2的命令手冊中的lock table命令, 此命令用于直接鎖表。

    隔離級別:

    下面讓我們來看一下隔離級別。 隔離級別主要用于控制在DB2根據應用提交的SQL語句向DB2數據庫中的相應對象加鎖時, 會鎖住哪些紀錄, 也就是鎖定的范圍。 隔離級別的不同, 鎖定的紀錄的范圍可能會有很大的差別。

    隔離級別分為RR/RS/CS/UR這四個級別。 下面讓我們來逐一論述:

    1. RR隔離級別: 在此隔離級別下, DB2會鎖住所有相關的紀錄。 在一個SQL語句執行期間, 所有執行此語句掃描過的紀錄都會被加上相應的鎖。 具體的鎖的類型還是由操作的類型來決定, 如果是讀取,則加共享鎖; 如果是更新, 則加獨占鎖。 由于會鎖定所有為獲得SQL語句的結果而掃描的紀錄, 所以鎖的數量可能會很龐大, 這個時候, 索引的增加可能會對SQL語句的執行有很大的影響,因為索引會影響SQL語句掃描的紀錄數量。

    2. RS隔離級別: 此隔離級別的要求比RR隔離級別稍弱,此隔離級別下會鎖定所有符合條件的紀錄。 不論是讀取, 還是更新, 如果SQL語句中包含查詢條件, 則會對所有符合條件的紀錄加相應的鎖。 如果沒有條件語句, 也就是對表中的所有記錄進行處理,則會對所有的紀錄加鎖。

    3. CS隔離級別: 此隔離級別僅鎖住當前處理的紀錄。

    4. UR隔離級別:此隔離級別下,如果是讀取操作,不會出現任何的行級鎖。對于非只讀的操作,它的鎖處理和CS相同。

    在這四種隔離級別中, CS是缺省值。 這四種隔離級別均可以保證DB2數據庫在并發的環境下不會有數據丟失的情況發生。 要注意的是如果對紀錄進行了修改,需要在相應的紀錄上加獨占類型的鎖, 這些獨占類型的鎖直到交易結束時才會被釋放, 這一點在四種隔離級別下都是相同的。

    posted @ 2006-08-22 12:07 MyJavaWorld 閱讀(885) | 評論 (0)編輯 收藏

    REORG TABLE

    REORG TABLE 語句壓縮與指定的表相關聯的數據。

    調用

    此語句可以在使用 DB2 CLI 函數的應用程序中使用,也可以通過 CLP 發出。

    語法

    >>-REORG TABLE--table-name--+------------+---------------------><
                                '-int1--int2-'
     
     
    

    描述

    REORG TABLE table-name
    標識重組操作的表。名稱必須標識現有的表。
    int1
    需要恢復的字節的可選最小百分比。
    int2
    需要為將要執行的表壓縮恢復的最小字節數。

    規則

    • 可選的值 int1int2 必須一起使用,或全都不用。
    • 可選的值 int1 必須是非負數。
    • 可選的值 int1 必須介于 0 與 100 之間。

    注意事項

    • DB2 Everyplace 可以以內部方式調用表重組。
    • 第一個可選參數是表必須包含的不可用的字節的百分比(即百分之十(10)意味“至少百分之十的空間不可用”。)第二個可選參數是表必須包含的不可用的字節數(即 1000 將意味“至少 1000 個字節必須是不可用的空間”。)必須符合兩個條件,才可以進行表的實際重組。
    • 如果沒有指定參數,DB2 Everyplace 對這此選項使用缺省值。缺省百分比是 30 且缺省字節是 6144。因此,“reorg table t1”與“reorg table t1 30 6144”相同。
    • 如果重組方式設置為已啟用,則 DB2 Everyplace 將自動重組表。如果在 DELETE 或 UPDATE 上啟用了重組,則在執行語句之后,會對目標表執行“reorg table table_name 50 30270”。如果在 DROP TABLE 上啟用了重組,則在刪除表處理結束時執行“reorg table DB2eSYSTABLES 30 10240”(對于 DB2eSYSCOLUMNS 和 DB2eSYSRELS 也是如此)。
    • 在 C/C++ 程序中,通過使用具有屬性 SQL_ATTR_REORG_MODE 的 CLI/ODBC 函數 SQLSetStmtAttr 設置重組方式。在 JAVA 程序中,通過 DB2eStatement 接口 enableReorg 方法設置重組方式。缺省值是啟用重組。
    • 重組表時,通過物理上回收刪除和更新創建的不可用空間來壓縮包含表的數據文件。然后將表的索引更新為指向行的新物理位置。
    • 可以重組“DB2 Everyplace 系統目錄”基本表。
    • 在執行 REORG TABLE 語句時,數據庫中不應發生任何其它活動。

    示例

    使用缺省值壓縮 VNNURSE 表。

    REORG TABLE VNNURSE?
    
    posted @ 2006-07-26 22:10 MyJavaWorld 閱讀(888) | 評論 (0)編輯 收藏
         摘要: 在數據庫應用程序中使用存儲過程有許多好處,包括減少對網絡的使用、提高性能以及降低開發成本。Java 存儲過程是 DB2 支持的最流行的例程之一。原因之一是,由于 Java 編程語言非常流行,所以 Java 開發人員非常多。因此,在有多種語言可供選擇時,Java 例程往往是首選的。 DB2 存儲過程不一定非用 Java 來編寫。如果業務邏輯只需要簡單的存儲過程,那么可以考慮用 ...  閱讀全文
    posted @ 2006-07-21 10:03 MyJavaWorld 閱讀(5620) | 評論 (0)編輯 收藏

    J***A正則表達式

    關鍵詞正則表達式 ?? ??????????????????????????????????????

    正則表達式

    。正則表達式(regular expression)是JDK 1.4的新功能,但是對sed和awk這樣的Unix的標準實用工具,以及Python,Perl之類的語言來講,它早就已經成為其不可或缺的組成部分了(有人甚至認為,它還是Perl能大獲成功的最主要的原因)。單從技術角度來講,正則表達式只是一種處理字符串的工具(過去Java這個任務是交由StringStringBuffer以及StringTokenizer處理的),但是它常常和I/O一起使用,所以放到這里來講也不算太離題吧。

    正則表達式是一種功能強大但又非常靈活的文本處理工具。它能讓你用編程的方式來描述復雜的文本模式,然后在字符串里把它找出來。一旦你找到了這種模式,你就能隨心所欲地處理這些文本了。雖然初看起來正則表達式的語法有點讓人望而生畏,但它提供了一種精練的動態語言,使我們能用一種通用的方式來解決各種字符串的問題,包括匹配,選擇,編輯以及校驗。

    創建正則表達式

    你可以從比較簡單的東西入手學習正則表達式。要想全面地掌握怎樣構建正則表達式,可以去看JDK文檔的java.util.regexPattern類的文檔。

    字符
    B字符B
    \xhh16進制值0xhh所表示的字符
    \uhhhh16進制值0xhhhh所表示的Unicode字符
    \tTab
    \n換行符
    \r回車符
    \f換頁符
    \eEscape

    正則表達式的強大體現在它能定義字符集(character class)。下面是一些最常見的字符集及其定義的方式,此外還有一些預定義的字符集:

    字符集
    .表示任意一個字符
    [abc]表示字符abc中的任意一個(與a|b|c相同)
    [^abc]abc之外的任意一個字符(否定)
    [a-zA-Z]azAZ當中的任意一個字符(范圍)
    [abc[hij]]a,b,c,h,i,j中的任意一個字符(與a|b|c|h|i|j相同)(并集)
    [a-z&&[hij]]h,i,j中的一個(交集)
    \s空格字符(空格鍵, tab, 換行, 換頁, 回車)
    \S非空格字符([^\s])
    \d一個數字,也就是[0-9]
    \D一個非數字的字符,也就是[^0-9]
    \w一個單詞字符(word character),即[a-zA-Z_0-9]
    \W一個非單詞的字符,[^\w]

    如果你用過其它語言的正則表達式,那么你一眼就能看出反斜杠的與眾不同。在其它語言里,"\\"的意思是"我只是要在正則表達式里插入一個反斜杠。沒什么特別的意思。"但是在Java里,"\\"的意思是"我要插入一個正則表達式的反斜杠,所以跟在它后面的那個字符的意思就變了。"舉例來說,如果你想表示一個或更多的"單詞字符",那么這個正則表達式就應該是"\\w+"。如果你要插入一個反斜杠,那就得用"\\\\"。不過像換行,跳格之類的還是只用一根反斜杠:"\n\t"。

    這里只給你講一個例子;你應該JDK文檔的java.util.regex.Pattern加到收藏夾里,這樣就能很容易地找到各種正則表達式的模式了。

    邏輯運算符
    XYX 后面跟著 Y
    X|YX或Y
    (X)一個"要匹配的組(capturing group)". 以后可以用\i來表示第i個被匹配的組。

    邊界匹配符
    ^一行的開始
    $一行的結尾
    \b一個單詞的邊界
    \B一個非單詞的邊界
    \G前一個匹配的結束

    舉一個具體一些的例子。下面這些正則表達式都是合法的,而且都能匹配"Rudolph":

    Rudolph
    [rR]udolph
    [rR][aeiou][a-z]ol.*
    R.*

    數量表示符

    "數量表示符(quantifier)"的作用是定義模式應該匹配多少個字符。

    • Greedy(貪婪的): 除非另有表示,否則數量表示符都是greedy的。Greedy的表達式會一直匹配下去,直到匹配不下去為止。(如果你發現表達式匹配的結果與預期的不符),很有可能是因為,你以為表達式會只匹配前面幾個字符,而實際上它是greedy的,因此會一直匹配下去。
    • Reluctant(勉強的): 用問號表示,它會匹配最少的字符。也稱為lazy, minimal matching, non-greedy, 或ungreedy。
    • Possessive(占有的): 目前只有Java支持(其它語言都不支持)。它更加先進,所以你可能還不太會用。用正則表達式匹配字符串的時候會產生很多中間狀態,(一般的匹配引擎會保存這種中間狀態,)這樣匹配失敗的時候就能原路返回了。占有型的表達式不保存這種中間狀態,因此也就不會回頭重來了。它能防止正則表達式的失控,同時也能提高運行的效率。
    GreedyReluctantPossessive匹配
    X?X??X?+匹配一個或零個X
    X*X*?X*+匹配零或多個X
    X+X+?X++匹配一個或多個X
    X{n}X{n}?X{n}+匹配正好n個X
    X{n,}X{n,}?X{n,}+匹配至少n個X
    X{n,m}X{n,m}?X{n,m}+匹配至少n個,至多m個X

    再提醒一下,要想讓表達式照你的意思去運行,你應該用括號把'X'括起來。比方說:

    abc+

    似乎這個表達式能匹配一個或若干個'abc',但是如果你真的用它去匹配'abcabcabc'的話,實際上只會找到三個字符。因為這個表達式的意思是'ab'后邊跟著一個或多個'c'。要想匹配一個或多個完整的'abc',你應該這樣:

    (abc)+

    正則表達式能輕而易舉地把你給耍了;這是一種建立在Java之上的新語言。

    CharSequence

    JDK 1.4定義了一個新的接口,叫CharSequence。它提供了StringStringBuffer這兩個類的字符序列的抽象:

    interface CharSequence {
      charAt(int i);
      length();
      subSequence(int start, int end);
      toString();
    }

    為了實現這個新的CharSequence接口,StringStringBuffer以及CharBuffer都作了修改。很多正則表達式的操作都要拿CharSequence作參數。

    PatternMatcher

    先給一個例子。下面這段程序可以測試正則表達式是否匹配字符串。第一個參數是要匹配的字符串,后面是正則表達式。正則表達式可以有多個。在Unix/Linux環境下,命令行下的正則表達式還必須用引號。

    當你創建正則表達式時,可以用這個程序來判斷它是不是會按照你的要求工作。

    //: c12:TestRegularExpression.java// Allows you to easly try out regular expressions.// {Args: abcabcabcdefabc "abc+" "(abc)+" "(abc){2,}" }import java.util.regex.*;
    publicclass TestRegularExpression {
      publicstaticvoid main(String[] args) {
        if(args.length < 2) {
          System.out.println("Usage:\n" +
            "java TestRegularExpression " +
            "characterSequence regularExpression+");
          System.exit(0);
        }
        System.out.println("Input: \"" + args[0] + "\"");
        for(int i = 1; i < args.length; i++) {
          System.out.println(
            "Regular expression: \"" + args[i] + "\"");
          Pattern p = Pattern.compile(args[i]);
          Matcher m = p.matcher(args[0]);
          while(m.find()) {
            System.out.println("Match \"" + m.group() +
              "\" at positions " +
              m.start() + "-" + (m.end() - 1));
          }
        }
      }
    } ///:~

    Java的正則表達式是由java.util.regexPatternMatcher類實現的。Pattern對象表示經編譯的正則表達式。靜態的compile( )方法負責將表示正則表達式的字符串編譯成Pattern對象。正如上述例程所示的,只要給Patternmatcher( )方法送一個字符串就能獲取一個Matcher對象。此外,Pattern還有一個能快速判斷能否在input里面找到regex的(注意,原文有誤,漏了方法名)

    staticboolean matches(?regex, ?input)

    以及能返回String數組的split( )方法,它能用regex把字符串分割開來。

    只要給Pattern.matcher( )方法傳一個字符串就能獲得Matcher對象了。接下來就能用Matcher的方法來查詢匹配的結果了。

    boolean matches()
    boolean lookingAt()
    boolean find()
    boolean find(int start)

    matches( )的前提是Pattern匹配整個字符串,而lookingAt( )的意思是Pattern匹配字符串的開頭。

    find( )

    Matcher.find( )的功能是發現CharSequence里的,與pattern相匹配的多個字符序列。例如:

    //: c12:FindDemo.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    import java.util.*;
    publicclass FindDemo {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) {
        Matcher m = Pattern.compile("\\w+")
          .matcher("Evening is full of the linnet's wings");
        while(m.find())
          System.out.println(m.group());
        int i = 0;
        while(m.find(i)) {
          System.out.print(m.group() + " ");
          i++;
        }
        monitor.expect(new String[] {
          "Evening",
          "is",
          "full",
          "of",
          "the",
          "linnet",
          "s",
          "wings",
          "Evening vening ening ning ing ng g is is s full " +
          "full ull ll l of of f the the he e linnet linnet " +
          "innet nnet net et t s s wings wings ings ngs gs s "
        });
      }
    } ///:~

    "\\w+"的意思是"一個或多個單詞字符",因此它會將字符串直接分解成單詞。find( )像一個迭代器,從頭到尾掃描一遍字符串。第二個find( )是帶int參數的,正如你所看到的,它會告訴方法從哪里開始找——即從參數位置開始查找。

    Groups

    Group是指里用括號括起來的,能被后面的表達式調用的正則表達式。Group 0 表示整個表達式,group 1表示第一個被括起來的group,以此類推。所以;

    A(B(C))D

    里面有三個group:group 0是ABCD, group 1是BC,group 2是C

    你可以用下述Matcher方法來使用group:

    public int groupCount( )返回matcher對象中的group的數目。不包括group0。

    public String group( ) 返回上次匹配操作(比方說find( ))的group 0(整個匹配)

    public String group(int i)返回上次匹配操作的某個group。如果匹配成功,但是沒能找到group,則返回null。

    public int start(int group)返回上次匹配所找到的,group的開始位置。

    public int end(int group)返回上次匹配所找到的,group的結束位置,最后一個字符的下標加一。

    下面我們舉一些group的例子:

    //: c12:Groups.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    publicclass Groups {
      privatestatic Test monitor = new Test();
      staticpublicfinal String poem =
        "Twas brillig, and the slithy toves\n" +
        "Did gyre and gimble in the wabe.\n" +
        "All mimsy were the borogoves,\n" +
        "And the mome raths outgrabe.\n\n" +
        "Beware the Jabberwock, my son,\n" +
        "The jaws that bite, the claws that catch.\n" +
        "Beware the Jubjub bird, and shun\n" +
        "The frumious Bandersnatch.";
      publicstaticvoid main(String[] args) {
        Matcher m =
          Pattern.compile("(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$")
            .matcher(poem);
        while(m.find()) {
          for(int j = 0; j <= m.groupCount(); j++)
            System.out.print("[" + m.group(j) + "]");
          System.out.println();
        }
        monitor.expect(new String[]{
          "[the slithy toves]" +
          "[the][slithy toves][slithy][toves]",
          "[in the wabe.][in][the wabe.][the][wabe.]",
          "[were the borogoves,]" +
          "[were][the borogoves,][the][borogoves,]",
          "[mome raths outgrabe.]" +
          "[mome][raths outgrabe.][raths][outgrabe.]",
          "[Jabberwock, my son,]" +
          "[Jabberwock,][my son,][my][son,]",
          "[claws that catch.]" +
          "[claws][that catch.][that][catch.]",
          "[bird, and shun][bird,][and shun][and][shun]",
          "[The frumious Bandersnatch.][The]" +
          "[frumious Bandersnatch.][frumious][Bandersnatch.]"
        });
      }
    } ///:~

    這首詩是Through the Looking Glass的,Lewis Carroll的"Jabberwocky"的第一部分。可以看到這個正則表達式里有很多用括號括起來的group,它是由任意多個連續的非空字符('\S+')和任意多個連續的空格字符('\s+')所組成的,其最終目的是要捕獲每行的最后三個單詞;'$'表示一行的結尾。但是'$'通常表示整個字符串的結尾,所以這里要明確地告訴正則表達式注意換行符。這一點是由'(?m)'標志完成的(模式標志會過一會講解)。

    start( )和end( )

    如果匹配成功,start( )會返回此次匹配的開始位置,end( )會返回此次匹配的結束位置,即最后一個字符的下標加一。如果之前的匹配不成功(或者沒匹配),那么無論是調用start( )還是end( ),都會引發一個IllegalStateException。下面這段程序還演示了matches( )lookingAt( )

    //: c12:StartEnd.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    publicclass StartEnd {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) {
        String[] input = new String[] {
          "Java has regular expressions in 1.4",
          "regular expressions now expressing in Java",
          "Java represses oracular expressions"
        };
        Pattern
          p1 = Pattern.compile("re\\w*"),
          p2 = Pattern.compile("Java.*");
        for(int i = 0; i < input.length; i++) {
          System.out.println("input " + i + ": " + input[i]);
          Matcher
            m1 = p1.matcher(input[i]),
            m2 = p2.matcher(input[i]);
          while(m1.find())
            System.out.println("m1.find() '" + m1.group() +
              "' start = "+ m1.start() + " end = " + m1.end());
          while(m2.find())
            System.out.println("m2.find() '" + m2.group() +
              "' start = "+ m2.start() + " end = " + m2.end());
          if(m1.lookingAt()) // No reset() necessary
            System.out.println("m1.lookingAt() start = "
              + m1.start() + " end = " + m1.end());
          if(m2.lookingAt())
            System.out.println("m2.lookingAt() start = "
              + m2.start() + " end = " + m2.end());
          if(m1.matches()) // No reset() necessary
            System.out.println("m1.matches() start = "
              + m1.start() + " end = " + m1.end());
          if(m2.matches())
            System.out.println("m2.matches() start = "
              + m2.start() + " end = " + m2.end());
        }
        monitor.expect(new String[] {
          "input 0: Java has regular expressions in 1.4",
          "m1.find() 'regular' start = 9 end = 16",
          "m1.find() 'ressions' start = 20 end = 28",
          "m2.find() 'Java has regular expressions in 1.4'" +
          " start = 0 end = 35",
          "m2.lookingAt() start = 0 end = 35",
          "m2.matches() start = 0 end = 35",
          "input 1: regular expressions now " +
          "expressing in Java",
          "m1.find() 'regular' start = 0 end = 7",
          "m1.find() 'ressions' start = 11 end = 19",
          "m1.find() 'ressing' start = 27 end = 34",
          "m2.find() 'Java' start = 38 end = 42",
          "m1.lookingAt() start = 0 end = 7",
          "input 2: Java represses oracular expressions",
          "m1.find() 'represses' start = 5 end = 14",
          "m1.find() 'ressions' start = 27 end = 35",
          "m2.find() 'Java represses oracular expressions' " +
          "start = 0 end = 35",
          "m2.lookingAt() start = 0 end = 35",
          "m2.matches() start = 0 end = 35"
        });
      }
    } ///:~

    注意,只要字符串里有這個模式,find( )就能把它給找出來,但是lookingAt( )matches( ),只有在字符串與正則表達式一開始就相匹配的情況下才能返回truematches( )成功的前提是正則表達式與字符串完全匹配,而lookingAt( )[67]成功的前提是,字符串的開始部分與正則表達式相匹配。

    匹配的模式(Pattern flags)

    compile( )方法還有一個版本,它需要一個控制正則表達式的匹配行為的參數:

    Pattern Pattern.compile(String regex, int flag)
    flag的取值范圍如下:
    編譯標志效果
    Pattern.CANON_EQ當且僅當兩個字符的"正規分解(canonical decomposition)"都完全相同的情況下,才認定匹配。比如用了這個標志之后,表達式"a\u030A"會匹配"?"。默認情況下,不考慮"規范相等性(canonical equivalence)"。
    Pattern.CASE_INSENSITIVE
    (?i)
    默認情況下,大小寫不明感的匹配只適用于US-ASCII字符集。這個標志能讓表達式忽略大小寫進行匹配。要想對Unicode字符進行大小不明感的匹配,只要將UNICODE_CASE與這個標志合起來就行了。
    Pattern.COMMENTS
    (?x)
    在這種模式下,匹配時會忽略(正則表達式里的)空格字符(譯者注:不是指表達式里的"\\s",而是指表達式里的空格,tab,回車之類)。注釋從#開始,一直到這行結束。可以通過嵌入式的標志來啟用Unix行模式。
    Pattern.DOTALL
    (?s)
    在這種模式下,表達式'.'可以匹配任意字符,包括表示一行的結束符。默認情況下,表達式'.'不匹配行的結束符。
    Pattern.MULTILINE
    (?m)
    在這種模式下,'^'和'$'分別匹配一行的開始和結束。此外,'^'仍然匹配字符串的開始,'$'也匹配字符串的結束。默認情況下,這兩個表達式僅僅匹配字符串的開始和結束。
    Pattern.UNICODE_CASE
    (?u)
    在這個模式下,如果你還啟用了CASE_INSENSITIVE標志,那么它會對Unicode字符進行大小寫不明感的匹配。默認情況下,大小寫不明感的匹配只適用于US-ASCII字符集。
    Pattern.UNIX_LINES
    (?d)
    在這個模式下,只有'\n'才被認作一行的中止,并且與'.','^',以及'$'進行匹配。

    在這些標志里面,Pattern.CASE_INSENSITIVEPattern.MULTILINE,以及Pattern.COMMENTS是最有用的(其中Pattern.COMMENTS還能幫我們把思路理清楚,并且/或者做文檔)。注意,你可以用在表達式里插記號的方式來啟用絕大多數的模式。這些記號就在上面那張表的各個標志的下面。你希望模式從哪里開始啟動,就在哪里插記號。

    可以用"OR" ('|')運算符把這些標志合使用:

    //: c12:ReFlags.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    publicclass ReFlags {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) {
        Pattern p =  Pattern.compile("^java",
          Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
        Matcher m = p.matcher(
          "java has regex\nJava has regex\n" +
          "J***A has pretty good regular expressions\n" +
          "Regular expressions are in Java");
        while(m.find())
          System.out.println(m.group());
        monitor.expect(new String[] {
          "java",
          "Java",
          "J***A"
        });
      }
    } ///:~

    這樣創建出來的正則表達式就能匹配以"java","Java","J***A"...開頭的字符串了。此外,如果字符串分好幾行,那它還會對每一行做匹配(匹配始于字符序列的開始,終于字符序列當中的行結束符)。注意,group( )方法僅返回匹配的部分。

    split( )

    所謂分割是指將以正則表達式為界,將字符串分割成String數組。

    String[] split(CharSequence charseq)
    String[] split(CharSequence charseq, int limit)

    這是一種既快又方便地將文本根據一些常見的邊界標志分割開來的方法。

    //: c12:SplitDemo.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    import java.util.*;
    publicclass SplitDemo {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) {
        String input =
          "This!!unusual use!!of exclamation!!points";
        System.out.println(Arrays.asList(
          Pattern.compile("!!").split(input)));
        // Only do the first three:
        System.out.println(Arrays.asList(
          Pattern.compile("!!").split(input, 3)));
        System.out.println(Arrays.asList(
          "Aha! String has a split() built in!".split(" ")));
        monitor.expect(new String[] {
          "[This, unusual use, of exclamation, points]",
          "[This, unusual use, of exclamation!!points]",
          "[Aha!, String, has, a, split(), built, in!]"
        });
      }
    } ///:~

    第二個split( )會限定分割的次數。

    正則表達式是如此重要,以至于有些功能被加進了String類,其中包括split( )(已經看到了),matches( )replaceFirst( )以及replaceAll( )。這些方法的功能同PatternMatcher的相同。

    替換操作

    正則表達式在替換文本方面特別在行。下面就是一些方法:

    replaceFirst(String replacement)將字符串里,第一個與模式相匹配的子串替換成replacement

    replaceAll(String replacement),將輸入字符串里所有與模式相匹配的子串全部替換成replacement

    appendReplacement(StringBuffer sbuf, String replacement)sbuf進行逐次替換,而不是像replaceFirst( )replaceAll( )那樣,只替換第一個或全部子串。這是個非常重要的方法,因為它可以調用方法來生成replacement(replaceFirst( )replaceAll( )只允許用固定的字符串來充當replacement)。有了這個方法,你就可以編程區分group,從而實現更強大的替換功能。

    調用完appendReplacement( )之后,為了把剩余的字符串拷貝回去,必須調用appendTail(StringBuffer sbuf, String replacement)

    下面我們來演示一下怎樣使用這些替換方法。說明一下,這段程序所處理的字符串是它自己開頭部分的注釋,是用正則表達式提取出來并加以處理之后再傳給替換方法的。

    //: c12:TheReplacements.javaimport java.util.regex.*;
    import java.io.*;
    import com.bruceeckel.util.*;
    import com.bruceeckel.simpletest.*;
    /*! Here's a block of text to use as input to
        the regular expression matcher. Note that we'll
        first extract the block of text by looking for
        the special delimiters, then process the
        extracted block. !*/publicclass TheReplacements {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) throws Exception {
        String s = TextFile.read("TheReplacements.java");
        // Match the specially-commented block of text above:
        Matcher mInput =
          Pattern.compile("/\\*!(.*)!\\*/", Pattern.DOTALL)
            .matcher(s);
        if(mInput.find())
          s = mInput.group(1); // Captured by parentheses// Replace two or more spaces with a single space:
        s = s.replaceAll(" {2,}", " ");
        // Replace one or more spaces at the beginning of each// line with no spaces. Must enable MULTILINE mode:
        s = s.replaceAll("(?m)^ +", "");
        System.out.println(s);
        s = s.replaceFirst("[aeiou]", "(VOWEL1)");
        StringBuffer sbuf = new StringBuffer();
        Pattern p = Pattern.compile("[aeiou]");
        Matcher m = p.matcher(s);
        // Process the find information as you// perform the replacements:while(m.find())
          m.appendReplacement(sbuf, m.group().toUpperCase());
        // Put in the remainder of the text:
        m.appendTail(sbuf);
        System.out.println(sbuf);
        monitor.expect(new String[]{
          "Here's a block of text to use as input to",
          "the regular expression matcher. Note that we'll",
          "first extract the block of text by looking for",
          "the special delimiters, then process the",
          "extracted block. ",
          "H(VOWEL1)rE's A blOck Of tExt tO UsE As InpUt tO",
          "thE rEgUlAr ExprEssIOn mAtchEr. NOtE thAt wE'll",
          "fIrst ExtrAct thE blOck Of tExt by lOOkIng fOr",
          "thE spEcIAl dElImItErs, thEn prOcEss thE",
          "ExtrActEd blOck. "
        });
      }
    } ///:~

    我們用前面介紹的TextFile.read( )方法來打開和讀取文件。mInput的功能是匹配'/*!' 和 '!*/' 之間的文本(注意一下分組用的括號)。接下來,我們將所有兩個以上的連續空格全都替換成一個,并且將各行開頭的空格全都去掉(為了讓這個正則表達式能對所有的行,而不僅僅是第一行起作用,必須啟用多行模式)。這兩個操作都用了StringreplaceAll( )(這里用它更方便)。注意,由于每個替換只做一次,因此除了預編譯Pattern之外,程序沒有額外的開銷。

    replaceFirst( )只替換第一個子串。此外,replaceFirst( )replaceAll( )只能用常量(literal)來替換,所以如果你每次替換的時候還要進行一些操作的話,它們是無能為力的。碰到這種情況,你得用appendReplacement( ),它能讓你在進行替換的時候想寫多少代碼就寫多少。在上面那段程序里,創建sbuf的過程就是選group做處理,也就是用正則表達式把元音字母找出來,然后換成大寫的過程。通常你得在完成全部的替換之后才調用appendTail( ),但是如果要模仿replaceFirst( )(或"replace n")的效果,你也可以只替換一次就調用appendTail( )。它會把剩下的東西全都放進sbuf

    你還可以在appendReplacement( )replacement參數里用"$g"引用已捕獲的group,其中'g' 表示group的號碼。不過這是為一些比較簡單的操作準備的,因而其效果無法與上述程序相比。

    reset( )

    此外,還可以用reset( )方法給現有的Matcher對象配上個新的CharSequence

    //: c12:Resetting.javaimport java.util.regex.*;
    import java.io.*;
    import com.bruceeckel.simpletest.*;
    publicclass Resetting {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) throws Exception {
        Matcher m = Pattern.compile("[frb][aiu][gx]")
          .matcher("fix the rug with bags");
        while(m.find())
          System.out.println(m.group());
        m.reset("fix the rig with rags");
        while(m.find())
          System.out.println(m.group());
        monitor.expect(new String[]{
          "fix",
          "rug",
          "bag",
          "fix",
          "rig",
          "rag"
        });
      }
    } ///:~

    如果不給參數,reset( )會把Matcher設到當前字符串的開始處。

    正則表達式與Java I/O

    到目前為止,你看到的都是用正則表達式處理靜態字符串的例子。下面我們來演示一下怎樣用正則表達式掃描文件并且找出匹配的字符串。受Unix的grep啟發,我寫了個JGrep.java,它需要兩個參數:文件名,以及匹配字符串用的正則表達式。它會把匹配這個正則表達式那部分內容及其所屬行的行號打印出來。

    //: c12:JGrep.java// A very simple version of the "grep" program.// {Args: JGrep.java "\\b[Ssct]\\w+"}import java.io.*;
    import java.util.regex.*;
    import java.util.*;
    import com.bruceeckel.util.*;
    publicclass JGrep {
      publicstaticvoid main(String[] args) throws Exception {
        if(args.length < 2) {
          System.out.println("Usage: java JGrep file regex");
          System.exit(0);
        }
        Pattern p = Pattern.compile(args[1]);
        // Iterate through the lines of the input file:
        ListIterator it = new TextFile(args[0]).listIterator();
        while(it.hasNext()) {
          Matcher m = p.matcher((String)it.next());
          while(m.find())
            System.out.println(it.nextIndex() + ": " +
              m.group() + ": " + m.start());
        }
      }
    } ///:~

    文件是用TextFile打開的(本章的前半部分講的)。由于TextFile會把文件的各行放在ArrayList里面,而我們又提取了一個ListIterator,因此我們可以在文件的各行當中自由移動(既能向前也可以向后)。

    每行都會有一個Matcher,然后用find( )掃描。注意,我們用ListIterator.nextIndex( )跟蹤行號。

    測試參數是JGrep.java和以[Ssct]開頭的單詞。

    還需要StringTokenizer嗎?

    看到正則表達式能提供這么強大的功能,你可能會懷疑,是不是還需要原先的StringTokenizer。JDK 1.4以前,要想分割字符串,只有用StringTokenizer。但現在,有了正則表達式之后,它就能做得更干凈利索了。

    //: c12:ReplacingStringTokenizer.javaimport java.util.regex.*;
    import com.bruceeckel.simpletest.*;
    import java.util.*;
    publicclass ReplacingStringTokenizer {
      privatestatic Test monitor = new Test();
      publicstaticvoid main(String[] args) {
        String input = "But I'm not dead yet! I feel happy!";
        StringTokenizer stoke = new StringTokenizer(input);
        while(stoke.hasMoreElements())
          System.out.println(stoke.nextToken());
        System.out.println(Arrays.asList(input.split(" ")));
        monitor.expect(new String[] {
          "But",
          "I'm",
          "not",
          "dead",
          "yet!",
          "I",
          "feel",
          "happy!",
          "[But, I'm, not, dead, yet!, I, feel, happy!]"
        });
      }
    } ///:~

    有了正則表達式,你就能用更復雜的模式將字符串分割開來——要是交給StringTokenizer的話,事情會麻煩得多。我可以很有把握地說,正則表達式可以取代StringTokenizer

    要想進一步學習正則表達式,建議你看Mastering Regular Expression, 2nd Edition,作者Jeffrey E. F. Friedl (O’Reilly, 2002)。

    總結

    Java的I/O流類庫應該能滿足你的基本需求:你可以用它來讀寫控制臺,文件,內存,甚至是Internet。你還可以利用繼承來創建新的輸入和輸出類型。你甚至可以利用Java會自動調用對象的toString( )方法的特點(Java僅有的"自動類型轉換"),通過重新定義這個方法,來對要傳給流的對象做一個簡單的擴展。

    但是Java的I/O流類庫及其文檔還是留下了一些缺憾。比方說你打開一個文件往里面寫東西,但是這個文件已經有了,這么做會把原先的內容給覆蓋了 。這時要是能有一個異常就好了——有些編程語言能讓你規定只能往新建的文件里輸出。看來Java是要你用File對象來判斷文件是否存在,因為如果你用FileOutputStreamFileWriter的話,文件就會被覆蓋了。

    我對I/O流類庫的評價是比較矛盾的;它確實能干很多事情,而且做到了跨平臺。但是如果你不懂decorator模式,就會覺得這種設計太難理解了,所以無論是對老師還是學生,都得多花精力。此外這個類庫也不完整,否則我也用不著去寫TextFile了。此外它沒有提供格式化輸出的功能,而其他語言都已經提供了這種功能。

    posted @ 2006-07-20 15:48 MyJavaWorld 閱讀(327) | 評論 (0)編輯 收藏
         摘要: Why is RUNSTATS important? Almost every major database today uses some method of updating catalog statistics to provide the best information possi...  閱讀全文
    posted @ 2006-06-23 15:40 MyJavaWorld 閱讀(454) | 評論 (0)編輯 收藏
    Abstract
    When you update table statistics using the RUNSTATS command, it requires that you run the command against each table, one by one. REORGCHK gives you the capability to update the statistics of a group of tables or all the tables in the database, with only one command.
    .
    Contents
    _
    DB2 UDB uses the statistics information in the catalog table to derive the best access plan. The DBA should regularly run the RUNSTATS command to keep the database statistics updated. This procedure will ensure the best performance on queries.

    If you want to update statistics on all the tables or a group of tables in the database, you can use the REORGCHK command with the UPDATE STATISTICS option. This would be run instead of running the RUNSTATS command against each table. The UPDATE STATISTICS option will first call the RUNSTATS routine to update the table statistic. You can then use these new statistics to determine if a reorg is needed.

    The REORGCHK command allows you to update statistics on a group of tables with one command.

    To update all the user and system tables use:

    REORGCHK UPDATE STATISTICS ON TABLE ALL

    To update all the tables of a particular schema use:

    REORGCHK UPDATE STATISTICS on SCHEMA schema_name

    To update all the tables of a particular table system use:

    REORGCHK UPDATE STATISTICS on TABLE SYSTEM
    posted @ 2006-06-23 15:19 MyJavaWorld 閱讀(476) | 評論 (0)編輯 收藏
    <html:radio idName=" idName "? value="value"? name=" name" property=" property " />
    表示在輸出時,html:radio輸出為input type="radio";name輸出為name="name";對
    于value的輸出,當不指定idName時,value="value",當指定idName時,輸出是由bean
    名為" idName ",屬性名為"value"的屬性值;當bean名為" name ",屬性名為" property "的屬性值等于上述value的輸出值時,輸出checked="checked"。
    我的例子:
    <logic:iterate id = "answer" name = "answerList" scope = "page">
    <html:radio idName = "answer" value = "answerItem" name = "question" property = "rightAnswer" ></html:radio>
    </logic:iterate>
    如果從bean answer的answerItem屬性中取出的值等于從bean question的rightAnswer
    屬性中取出的值相等,那么該radio將被選中

    posted @ 2006-06-21 16:54 MyJavaWorld 閱讀(1422) | 評論 (0)編輯 收藏

    1. 一個表如果建有大量索引會影響 INSERT、UPDATE 和 DELETE 語句的性能,因為在表中的數據更改時,所有索引都須進行適當的調整。另一方面,對于不需要修改數據的查詢(SELECT 語句),大量索引有助于提高性能,因為數據庫有更多的索引可供選擇,以便確定以最快速度訪問數據的最佳方法。

    2. 組合索引:組合索引即多列索引,指一個索引含有多個列。一個組合索引相當于多個單列索引,如索引(ColA, ColB, ColC)至少相當于(ColA)、(ColA, ColB)、(ColA, ColB, ColC)三個索引。

    2. 覆蓋的查詢可以提高性能。覆蓋的查詢是指查詢中所有指定的列都包含在同一個索引(組合索引)中。例如,如果在一個表的 a、b 和 c 列上創建了組合索引,則從該表中檢索 a 和 b 列的查詢被視為覆蓋的查詢。創建覆蓋一個查詢的索引可以提高性能,因為該查詢的所有數據都包含在索引自身當中;檢索數據時只需引用表的索引頁,不必引用數據頁,因而減少了 I/O 總量。盡管給索引添加列以覆蓋查詢可以提高性能,但在索引中額外維護更多的列會產生更新和存儲成本。

    3. 對小型表進行索引可能不會產生優化效果,因為數據庫在遍歷索引以搜索數據時,花費的時間可能會比簡單的表掃描還長。

    4. 應使用 SQL 事件探查器和索引優化向導幫助分析查詢,確定要創建的索引。為數據庫及其工作負荷選擇正確的索引是非常復雜的,需要在查詢速度和更新成本之間取得平衡。窄索引(搜索關鍵字中只有很少的列的索引)需要的磁盤空間和維護開銷都更少。而另一方面,寬索引可以覆蓋更多的查詢。確定正確的索引集沒有簡便的規則。經驗豐富的數據庫管理員常常能夠設計出很好的索引集,但是,即使對于不特別復雜的數據庫和工作負荷來說,這項任務也十分復雜、費時和易于出錯。可以使用索引優化向導使這項任務自動化。有關更多信息,請參見索引優化向導。

    5. 可以在視圖上指定索引。

    6. 可以在計算列上指定索引。

    7. 避免在索引列上使用IS NULL和IS NOT NULL。避免在索引中使用任何可以為空的列,數據庫將無法使用該索引。對于單列索引,如果列包含空值,索引中將不存在此記錄;對于復合索引,如果每個列都為空,索引中同樣不存在此記錄. 如果至少有一個列不為空,則記錄存在于索引中。

    8. 如果經常檢索包含大量數據的表中的少于15%的行則需要創建索引。

    9. 衡量索引效率的 95/5 規則:如果查詢的結果返回的行數少于表中所有行的5%,則索引是檢索數據的最快方法,如果查詢的結果超過5%,那么通常使用索引就不是最快的方式。

    10.主關鍵字和唯一關鍵字所在的列自動具有索引,但外部關鍵字沒有自動索引。


    二、索引的特征
    ??? 在確定某一索引適合某一查詢之后,可以自定義最適合具體情況的索引類型。索引特征包括:

    ●聚集還是非聚集
    ●唯一還是不唯一
    ●單列還是多列
    ●索引中的列順序為升序還是降序(索引缺省為升序,但目前多數大型數據庫已經能夠支持反向索引)
    ●覆蓋還是非覆蓋
    ●還可以自定義索引的初始存儲特征,通過設置填充因子優化其維護,并使用文件和文件組自定義其位置以優化性能。
    ●位映射索引(bitmap)

    posted @ 2006-06-21 16:50 MyJavaWorld 閱讀(2281) | 評論 (0)編輯 收藏
    主站蜘蛛池模板: 亚洲色欲色欲www在线丝| 最近2019中文免费字幕| 国产一区二区三区免费观看在线| 免费夜色污私人影院网站| 91精品免费不卡在线观看| 外国成人网在线观看免费视频| 亚洲AV综合色区无码二区爱AV| 亚洲黄色三级网站| 亚洲视频欧洲视频| 亚洲中文字幕久在线| 国产成人亚洲合集青青草原精品| 亚洲欧洲日韩国产一区二区三区| 亚洲日韩精品射精日| 亚洲第一极品精品无码久久| 亚洲激情中文字幕| 亚洲精品乱码久久久久久下载| 亚洲国产精品人久久电影| 亚洲欧洲日产国码av系列天堂| 亚洲日韩乱码中文无码蜜桃臀网站| 亚洲精品无码成人AAA片| 亚洲成AV人片在WWW色猫咪| 91亚洲国产成人久久精品网站| 亚洲国产日韩女人aaaaaa毛片在线| 亚洲欧洲成人精品香蕉网| 亚洲AV人人澡人人爽人人夜夜| 久久亚洲中文字幕精品有坂深雪| 国产AV无码专区亚洲AWWW | 亚洲日韩中文字幕| 亚洲色少妇熟女11p| 一级**爱片免费视频| 精品在线免费观看| 2022国内精品免费福利视频| 亚洲av第一网站久章草| 草久免费在线观看网站| 色吊丝免费观看网站| 中文字幕亚洲综合久久综合| 精品女同一区二区三区免费播放| 亚洲精品欧美综合四区| 亚洲砖码砖专无区2023| 男人和女人高潮免费网站 | 无码天堂va亚洲va在线va|