??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲va中文字幕无码,亚洲视屏在线观看,国产av无码专区亚洲av毛片搜http://www.tkk7.com/xiaoxiaoyupku/category/4855.htmlAt times , people will simply not come through for you in the way you need.Forgive them and move on.zh-cnFri, 02 Mar 2007 07:37:14 GMTFri, 02 Mar 2007 07:37:14 GMT60触发器与存储q程http://www.tkk7.com/xiaoxiaoyupku/articles/88670.html潇潇?/dc:creator>潇潇?/author>Tue, 19 Dec 2006 00:57:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/88670.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/88670.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/88670.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/88670.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/88670.html --触发器如何调用存储过E?/em>
create trigger test on table
for insert
as
exec 存储q程?br />go

--存储q程如何调用触发?
create proc test
as
update table set ...
insert table select ...
delete table ...

--我们有一个table如下Q需要跟t修改对该表的insert/update/delete操作Q?br />
create table testMonitor(c1 int, c2 char(10))


--创徏的辅助表如下Q?br />
create table tempLog_testMonitor(
rowID bigint identity(1,1),
hostname nchar(128),
program_name nchar(128),
nt_domain nchar(128),
nt_username nchar(128),
net_address nchar(12),
loginame nchar(128),
login_time datetime,
EventType nvarchar(30),
parameters int,
EventInfo nvarchar(255)
)

--创徏的trigger如下Q?br />
create trigger trg_testMonitor
on testMonitor
for insert,update,delete
as
begin

            declare @hostname nchar(128)
            declare @program_name nchar(128) 
            declare @nt_domain nchar(128) 
            declare @nt_username nchar(128) 
            declare @net_address nchar(12)
            declare @loginame nchar(128)
            declare @login_time datetime
            declare @rowID bigint

            
            insert into tempLog_testMonitor(EventType,parameters,EventInfo)
            exec ('dbcc inputbuffer(@@spid)')
            select @rowID = scope_identity()                  
            select  @hostname = hostname,
                        @program_name = program_name,
                        @nt_domain = nt_domain,
                        @nt_username = nt_username,
                        @net_address = net_address,
                        @loginame = loginame,
                        @login_time = login_time
            from master..sysprocesses where spid = @@spid

            update tempLog_testMonitor set 
            hostname = @hostname,
            program_name = @program_name,
            nt_domain = @nt_domain,
            nt_username = @nt_username,
            net_address = @net_address,
            loginame = @loginame,
            login_time = @login_time
            where rowID = @rowID
end

--如果我们执行如下的语句:

insert into testmonitor values(1,'aaa')
update testmonitor set c2 = 'bbb'
delete from testmonitor

--您再查询辅助表,p看到对表修改的相关信息:

select * from tempLog_testMonitor



]]>
Troubleshooting Problems With the Informix Databasehttp://www.tkk7.com/xiaoxiaoyupku/articles/82422.html潇潇?/dc:creator>潇潇?/author>Mon, 20 Nov 2006 19:18:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/82422.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/82422.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/82422.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/82422.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/82422.html Troubleshooting Problems With the Informix Database

Problems with the database usually result in messages being written to the Informix message log, which is stored in /usr/sgi/informix/online.log. You should monitor this file periodically. In addition, if problems with the database occur, view this message log for relevant information.

This section describes how to troubleshoot problems with the Informix database. The following topics are discussed:

You can find additional information about Informix in these sections:

Running Out of Space

If the Informix database runs out of space, you will see a message in the Informix log (/usr/sgi/informix/online.log) that is similar to the following:

SQLSTATE IX000: ISAM error: no free disk space

By default, the Informix database information is stored in /usr/sgi/informix/data/root_chunk. To add more space to the database without bringing down MediaBase or the Informix server:

  1. Log into the host as informix by entering the following:

    # su - informix

  2. Make sure there is enough space on the filesystem where the extension to root_chunk will be located. (In this procedure, the name of the space that will be added is called extend_root_chunk.)

  3. Touch the file extend_root_chunk by entering the following:

    # touch extend_root_chunk

  4. Make sure the file is owned by informix by entering the following:

    # chown informix.informix extend_root_chunk

  5. Allow the extend_root_chunk file to be read and written to by Informix, by entering the following:

    # chmod 660 extend_root_chunk

  6. Add a 200 megabyte extension named extend_root_chunk to the database by entering the following:

    # setenv INFORMIXSERVER odlshm

    # setenv INFORMIXDIR /usr/sgi/informix

    # cd /usr/sgi/informix/bin

    # onspaces -a rootdbs -p absolutePath -o 0 -s 200000

    absolutePath is the absolute pathname of the location of extend_root_chunk, for example, /usr/sgi/informix/data/extend_root_chunk.

    Wait until you see messages similar to the following:

    Adding chunk...

    Successfully Added chunk...

    #

    When you see these messages, the Informix server knows it has the additional space and will use it automatically.

Running Out of Locks

If the Informix database runs out of locks, you will see many messages in the Informix log (/usr/sgi/informix/online.log) similar to the following:

19:58:09  Lock table overflow - user id 55555, session id 1691

Note: One or a few messages like this in the log are normal. A problem exists only if you see this message many times.

To recover from this problem:

  1. Log into the server host as root, or become the superuser by entering the su command.

  2. Stop MediaBase and Informix by entering the following:

    # /etc/init.d/mediabase stop

    # /etc/init.d/informix stop

    If Informix does not stop, you can stop it by entering the following:

    # killall oninit

  3. Determine whether any shared memory segments exist by entering the following:

    # ipcs -ma

    If any shared memory segments belong to Informix, you will see output that looks similar to the following:

    IPC status from /dev/kmem as of Tue Jul 23 21:21:04 1996

    T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME

    Shared Memory:

    m 1202 0x52564801 --rw-rw---- root informix root informix 12 5054464 16912 19696 21:21:00 21:21:01 20:23:00

    m 1203 0x52564802 --rw-rw---- root informix root informix 12 8192000 16912 19696 21:21:00 21:21:01 20:23:00

    m 1204 0x52564803 --rw-rw-rw- root informix root informix 14 622592 16912 19696 21:21:00 21:21:01 20:23:10

    m 1206 0x52564804 --rw-rw---- root informix root informix 12 8388608 16912 19696 21:21:00 21:21:01 20:41:38

  4. If any segments belong to Informix, as seen in step 3, remove all the segments, one at a time, by entering the following for each segment:

    # ipcrm -m SHARED_MEMORY_SEGMENT_ID

    For example, the following removes the segment whose shared memory ID is 1202:

    # ipcrm -m 1202

  5. Start Informix by entering the following command:

    # /etc/init.d/informix start

  6. Start MediaBase by entering the following command:

    # /etc/init.d/mediabase start

Shared Memory Creation Error

You may see the following message when initializing the database:

oninit: Fatal error in shared memory creation

Two conditions can cause this error:

  • Informix is already running when you try to initialize the database or start the Informix server. If this is the case you can ignore the message.

  • Memory segments were not cleaned up after an Informix crash or other failure. If this is the case, you must clean up the shared memory segments.

To recover from the error condition:

  1. Use one of the following commands to check if Informix is running:

    • # ps -ef | grep oninit

      If Informix is running, you will see many processes.

    • /usr/mbase/sbin/chkserveron

      If Informix is running, you will see the message ODL server ready.

  2. If the server is not running:

    • Determine whether any shared memory segments exist by entering the following:

      # ipcs -ma

      If any shared memory segments belong to Informix, you see output that looks similar to the following:

      IPC status from /dev/kmem as of Tue Jul 23 21:21:04 1996

      T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME

      Shared Memory:

      m 1202 0x52564801 --rw-rw---- root informix root informix 12 5054464 16912 19696 21:21:00 21:21:01 20:23:00

      m 1203 0x52564802 --rw-rw---- root informix root informix 12 8192000 16912 19696 21:21:00 21:21:01 20:23:00

      m 1204 0x52564803 --rw-rw-rw- root informix root informix 14 622592 16912 19696 21:21:00 21:21:01 20:23:10

      m 1206 0x52564804 --rw-rw---- root informix root informix 12 8388608 16912 19696 21:21:00 21:21:01 20:41:38

    • If any segments belong to Informix, as seen above, remove all the segments, one at a time, by entering the following for each segment:

      # ipcrm -m SHARED_MEMORY_SEGMENT_ID

      For example, the following removes the segment whose shared memory ID is 1202:

      # ipcrm -m 1202

  3. Restart or reinitialize the database.

posuser Error Message

If you see a message that posuser is not found, the MediaBase system is probably using a shadow password file. To fix this, use the IRIX pwconv utility to install and update /etc/shadow with the information in /etc/passwd.

Cannot Connect Error Message

If you see a message such as cannot open or cannot connect, suspect:

  • the database is not correctly configured or set up

  • a corrupt database file

Make sure to configure the event logging threshold to debug.


Running Out of Space
Running Out of Locks
Shared Memory Creation Error
posuser Error Message
Cannot Connect Error Message

Next | Prev | Up | Top | Contents | Index


]]>
one solution of informix shared memory error == but I am not sure about thishttp://www.tkk7.com/xiaoxiaoyupku/articles/81893.html潇潇?/dc:creator>潇潇?/author>Fri, 17 Nov 2006 23:38:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/81893.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/81893.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/81893.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/81893.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/81893.html

I'm a programmer, but I need to install IDS 7.31

I have one server compaq (intel pentium) with Unixware 7.1.1

I read the documentation but my problem continues.

When I start the Database server with the 'oninit -i' instruction, I see the next error:

"oninit: Fatal error in shared memory creation"

Somebody help me, please¡

Sorry for my english.

Helpful Member! appi (IS/IT--Management)
8 Jul 04 4:00
Hi,

take a look in the ONCONFIG which logfile you've specified.
In that logfile maybe an error during startup is reported.
Paramater in Onconfig is MSGPATH
Pls report the error over there and we may help you
coquito65 (Programmer)
8 Jul 04 12:58
OK.

This is the error message:

11:50:11  shmget: [EEXIST][17]: key 52574801: shared memory already exists
11:50:11  mt_shm_init: can't create resident segment

Thanks appi ¡
ids2000 (TechnicalUser)
3 Aug 04 10:26
The problem is that probably you have tried to bring the engine up too many times, and so has locked some
shared memory segments on your OS.
Try this:

ipcs -m|grep informix

See if there is any memory segments there, if so, try this:

ipcrm -m <shmid>
where <shmid> is the number on the second column.

After that, cut and paste the output from onstat -

FFO
"The only way of knowing is to understand"



]]>
how to set right ownship and permissions for files in informix ? ----- need to be answeredhttp://www.tkk7.com/xiaoxiaoyupku/articles/81891.html潇潇?/dc:creator>潇潇?/author>Fri, 17 Nov 2006 21:20:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/81891.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/81891.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/81891.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/81891.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/81891.htmlfor now, I only know there are two users in informix, namely root and informix. root is more powerful than informix. when you install your IDS you need to use root account, and all the files like onconfig file, sqlhosts file, dbspaces trunk files, data bakup file, logic log bakup file, alarm program and so on, all these files need to have informix group and informix user ownship, and should have no more nor less 660 permission. but I am now still confusing about when should access using root account and when should use informix account, and how to set up group and users if no use ISA?



]]>
sql语句插入的数据中含有单引h么办?http://www.tkk7.com/xiaoxiaoyupku/articles/45078.html潇潇?/dc:creator>潇潇?/author>Mon, 08 May 2006 12:27:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/45078.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/45078.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/45078.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/45078.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/45078.html

]]>
[数据库]oracle 日期cd字段的操?转蝲自http://blogger.org.cn/blog/more.asp?name=dashee&id=6452)http://www.tkk7.com/xiaoxiaoyupku/articles/42800.html潇潇?/dc:creator>潇潇?/author>Mon, 24 Apr 2006 03:20:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/42800.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/42800.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/42800.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/42800.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/42800.html

ideation 发表?2005-6-8 16:26:22

在java对oracle的操作中Q日期字D|很头疼的事情Q其实仔l研I一下也q不难掌握?/p>

举个例子来说明:

?book  中有name varchar2(20)//书籍名称,buydate Date //购买日期 两个字段?/p>

已经创徏了数据库q接Connection conn;

Ҏ一、用java.sql.Date实现比较单的yyyy-mm-dd格式日期?/p>

java.sql.Date不支持时间格式。切C要用new java.sql.Date(int year,int month,int date),因ؓq要处理旉差问题?/p>

PreparedStatement pstmt = conn.prepareStatement("insert into book (name,buydate) values (?,?)");

java.sql.Date buydate=java.sql.Date.valueOf("2005-06-08");
pstmt.setString(1, "Java~程思想");
pstmt.setDate(2,buydate );
pstmt.execute();

Ҏ二、用java.sql.Timestamp,同上不用new Timestamp(....)

PreparedStatement pstmt = conn.prepareStatement("insert into book (name,buydate) values (?,?)");

java.sql.Timestamp buydate=java.sql.Timestamp.valueOf("2004-06-08 05:33:99");
pstmt.setString(1, "Java~程思想");
pstmt.setTimestamp(2,buydate );
pstmt.execute();

Ҏ三、用oracle 的to_date内置函数

PreparedStatement pstmt = conn.prepareStatement("insert into book (name,buydate) values (?,to_date(?, 'yyyy-mm-dd hh24:mi:ss')");

String buydate="2004-06-08 05:33:99";
pstmt.setString(1, "Java~程思想");
pstmt.setString(2,buydate );
pstmt.execute();

?oracle日期格式参数 含义说明  
d: 一周中的星期几  
day: 天的名字Q用空格填充到9个字W ?br />dd: 月中的第几天  
ddd: q中的第几天  
dy: 天的写名  
iw: ISO标准的年中的W几周 ?br />iyyy: ISO标准的四位年q?br />yyyy: 四位q䆾  
yyy,yy,y: q䆾的最后三位,两位Q一位 ?br />hh: 时Q按12时计 ?br />hh24: 时Q按24时计 ?br />mi: 分 ?br />ss: U ?br />mm: 月 ?br />mon: 月䆾的简写 ?br />month: 月䆾的全名 ?br />w: 该月的第几个星期  
ww: q中的第几个星期

到此刻,你应该烦恼已消,L了很多吧?/p>



]]>
oracle与java中datecdQ汇总)待箋http://www.tkk7.com/xiaoxiaoyupku/articles/42736.html潇潇?/dc:creator>潇潇?/author>Sun, 23 Apr 2006 15:26:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/42736.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/42736.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/42736.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/42736.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/42736.html一、在使用Oracle的to_date函数来做日期转换Ӟ很多JavaE序员也怼和我一P直觉的采用“yyyy-MM-dd HH:mm:ss”的格式作ؓ格式q行转换Q但是在Oracle中会引v错误Q“ORA 01810 格式代码出现两次”?br />如:select to_date('2005-01-01 13:14:20','yyyy-MM-dd HH24:mm:ss') from dual;
原因是SQL中不区分大小写,MM和mm被认为是相同的格式代码,所以Oracle的SQL采用了mi代替分钟?br />select to_date('2005-01-01 13:14:20','yyyy-MM-dd HH24:mi:ss') from dual;

二、另要以24时的Ş式显C出来要用HH24
select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;//mi是分?br />select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') from dual;//mm会显C月?img src ="http://www.tkk7.com/xiaoxiaoyupku/aggbug/42736.html" width = "1" height = "1" />

]]>
sql备䆾http://www.tkk7.com/xiaoxiaoyupku/articles/24614.html潇潇?/dc:creator>潇潇?/author>Mon, 19 Dec 2005 04:31:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/24614.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/24614.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/24614.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/24614.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/24614.htmldelete from data_dmd_data;
delete from data_dmd_data_simple;
delete from data_meta_info;
delete from index_maintable;
delete from index_metaid_mapping;
delete from rep_item_navg_index;
 
select count(*) from data_dmd_data;
select count(*) from data_dmd_data_simple;
select count(*) from data_meta_info;
select count(*) from index_maintable;
select count(*) from index_metaid_mapping;
select count(*) from rep_item_navg_index;
 
76697  101843


]]>
通过JDBCq接oracle数据库的十大技?http://www.tkk7.com/xiaoxiaoyupku/articles/20756.html潇潇?/dc:creator>潇潇?/author>Mon, 21 Nov 2005 05:46:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/20756.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/20756.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/20756.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/20756.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/20756.html    
    Java数据库连接(JDBCQAPI是一pd能够让Java~程人员讉K数据库的接口Q各个开发商的接口ƈ不完全相同。在使用多年的Oracle公司的JDBC后,我积累了许多技巧,q些技巧能够我们更好地发挥系l的性能和实现更多的功能?

  1、在客户端Y件开发中使用Thin驱动E序

  在开发Java软g斚wQOracle的数据库提供了四U类型的驱动E序Q二U用于应用Y件、applets、servlets{客L软gQ另外二U用于数据库中的Java存储q程{服务器端Y件。在客户机端软g的开发中Q我们可以选择OCI驱动E序或Thin驱动E序。OCI驱动E序利用Java本地化接口(JNIQ,通过Oracle客户端Y件与数据库进行通讯。Thin驱动E序是纯Java驱动E序Q它直接与数据库q行通讯。ؓ了获得最高的性能QOracle在客L软g的开发中使用OCI驱动E序Q这g是正的。但我徏议用Thin驱动E序Q因为通过多次试发现Q在通常情况下,Thin驱动E序的性能都超q了OCI驱动E序?

  2、关闭自动提交功能,提高pȝ性能

  在第一ơ徏立与数据库的q接Ӟ在缺省情况下Q连接是在自动提交模式下的。ؓ了获得更好的性能Q可以通过调用带布值false参数的ConnectioncȝsetAutoCommit()Ҏ关闭自动提交功能Q如下所C:

  conn.setAutoCommit(false);

  值得注意的是Q一旦关闭了自动提交功能Q我们就需要通过调用Connectioncȝcommit()和rollback()Ҏ来h工的方式对事务进行管理?

  3、在动态SQL或有旉限制的命令中使用Statement对象

  在执行SQL命oӞ我们有二U选择Q可以用PreparedStatement对象Q也可以使用Statement对象。无论多次C用同一个SQL命oQPreparedStatement都只对它解析和编译一ơ。当使用Statement对象Ӟ每次执行一个SQL命oӞ都会对它q行解析和编译。这可能会你认为,使用PreparedStatement对象比用Statement对象的速度更快。然而,我进行的试表明Q在客户端Y件中Q情况ƈ非如此。因此,在有旉限制的SQL操作中,除非成批地处理SQL命oQ我们应当考虑使用Statement对象?

  此外Q用Statement对象也得编写动态SQL命o更加单,因ؓ我们可以字W串q接在一P建立一个有效的SQL命o。因此,我认为,Statement对象可以使动态SQL命o的创建和执行变得更加单?

  4、利用helper函数对动态SQL命oq行格式?

  在创Z用Statement对象执行的动态SQL命oӞ我们需要处理一些格式化斚w的问题。例如,如果我们惛_Z个将名字O'Reilly插入表中的SQL命oQ则必须使用二个相连的?'”号替换O'Reilly中的?”号。完成这些工作的最好的Ҏ是创Z个完成替换操作的helperҎQ然后在q接字符串心服用公式表达一个SQL命oӞ使用创徏的helperҎ。与此类似的是,我们可以让helperҎ接受一个Date型的|然后让它输出ZOracle的to_date()函数的字W串表达式?

  5、利用PreparedStatement对象提高数据库的M效率

  在用PreparedStatement对象执行SQL命oӞ命o被数据库q行解析和编译,然后被放到命令缓冲区。然后,每当执行同一个PreparedStatement对象Ӟ它就会被再解析一ơ,但不会被再次~译。在~冲Z可以发现预编译的命oQƈ且可以重C用。在有大量用L企业U应用Y件中Q经怼重复执行相同的SQL命oQ用PreparedStatement对象带来的编译次数的减少能够提高数据库的M性能。如果不是在客户端创建、预备、执行PreparedStatementd需要的旉长于StatementdQ我会徏议在除动态SQL命o之外的所有情况下使用PreparedStatement对象?

  6、在成批处理重复的插入或更新操作中用PreparedStatement对象

  如果成批地处理插入和更新操作Q就能够显著地减它们所需要的旉。Oracle提供的Statement?CallableStatementq不真正地支持批处理Q只有PreparedStatement对象才真正地支持批处理。我们可以用addBatch()和executeBatch()Ҏ选择标准的JDBC批处理,或者通过利用PreparedStatement对象的setExecuteBatch()Ҏ和标准的executeUpdate()Ҏ选择速度更快的Oracle专有的方法。要使用Oracle专有的批处理机制Q可以以如下所C的方式调用setExecuteBatch()Q?

PreparedStatement pstmt3D null;
try {
((OraclePreparedStatement)
pstmt).setExecuteBatch(30);
...
pstmt.executeUpdate();
}

  调用setExecuteBatch()时指定的值是一个上限,当达到该值时Q就会自动地引发SQL命o执行Q标准的executeUpdate()Ҏ׃被作为批处理送到数据库中。我们可以通过调用PreparedStatementcȝsendBatch()Ҏ随时传输批处理Q务?

  7、用Oracle locatorҎ插入、更新大对象QLOBQ?

  Oracle的PreparedStatementcM完全支持BLOB和CLOB{大对象的处理,其是Thin驱动E序不支持利用PreparedStatement对象的setObject()和setBinaryStream()Ҏ讄BLOB的|也不支持利用setCharacterStream()Ҏ讄CLOB的倹{只有locator本n中的Ҏ才能够从数据库中获取LOBcd的倹{可以用PreparedStatement对象插入或更新LOBQ但需要用locator才能获取LOB的倹{由于存在这二个问题Q因此,我徏议用locator的方法来插入、更新或获取LOB的倹{?

  8、用SQL92语法调用存储q程

  在调用存储过E时Q我们可以用SQL92或Oracle PL/SQLQ由于用Oracle PL/SQLq没有什么实际的好处Q而且会给以后l护你的应用E序的开发h员带来麻烦,因此Q我在调用存储过E时使用SQL92?

  9、用Object SQL对象模式{Ud数据库中

  既然可以Oracle的数据库作ؓ一U面向对象的数据库来使用Q就可以考虑应用程序中的面向对象模式{到数据库中。目前的Ҏ是创建Java bean作ؓ伪装的数据库对象Q将它们的属性映到关系表中Q然后在q些bean中添加方法。尽这样作在Java中没有什么问题,但由于操作都是在数据库之外进行的Q因此其他访问数据库的应用Y件无法利用对象模式。如果利用Oracle的面向对象的技术,可以通过创徏一个新的数据库对象cd在数据库中模仿其数据和操作,然后使用JPublisher{工L成自qJava beancR如果用这U方式,不但Java应用E序可以使用应用软g的对象模式,其他需要共享你的应用中的数据和操作的应用Y件也可以使用应用软g中的对象模式?

  10、利用SQL完成数据库内的操?

  我要向大家介l的最重要的经验是充分利用SQL的面向集合的Ҏ来解x据库处理需求,而不是用Java{过E化的编E语a?

  如果~程人员要在一个表中查找许多行Q结果中的每个行都会查找其他表中的数据,最后,~程人员创徏了独立的UPDATE命o来成批地更新W一个表中的数据。与此类似的d可以通过在set子句中用多列子查询而在一个UPDATE命o中完成。当能够在单一的SQL命o中完成Q务,何必要让数据在网上流来流ȝQ我用户认真学习如何最大限度地发挥SQL的功能?BR>

]]>
通过JDBC操纵Oracle数据库LOB字段的几U情况分?/title><link>http://www.tkk7.com/xiaoxiaoyupku/articles/20062.html</link><dc:creator>潇潇?/dc:creator><author>潇潇?/author><pubDate>Wed, 16 Nov 2005 07:04:00 GMT</pubDate><guid>http://www.tkk7.com/xiaoxiaoyupku/articles/20062.html</guid><wfw:comment>http://www.tkk7.com/xiaoxiaoyupku/comments/20062.html</wfw:comment><comments>http://www.tkk7.com/xiaoxiaoyupku/articles/20062.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/20062.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/20062.html</trackback:ping><description><![CDATA[<FONT color=#008000>    在Oracle中,LOBQLarge ObjectQ大型对象)cd的字D늎在用得越来越多了。因U类型的字段Q容量大Q最多能容纳4GB的数据)Q且一个表中可以有多个q种cd的字D,很灵z,适用于数据量非常大的业务领域Q如图象、案等Q。而LONG、LONG RAW{类型的字段Q虽然存储容量也不小Q可?GBQ,但由于一个表中只能有一个这L型的字段的限Ӟ现在已很用了?<BR>    LOBcd分ؓBLOB和CLOB两种QBLOB即二q制大型对象QBinary Large ObjectQ,适用于存贮非文本的字节流数据Q如E序、图象、媄音等Q。而CLOBQ即字符型大型对象(Character Large ObjectQ,则与字符集相养I适于存贮文本型的数据Q如历史档案、大部头著作{)?BR>    下面以程序实例说明通过JDBC操纵Oracle数据库LOBcd字段的几U情c?BR>    先徏立如下两个测试用的数据库表,Power Designer PD模型如下Q?BR><BR>               <IMG src="http://www.jcwcn.com/news/UploadFiles_5180/200509/20050922154245343.jpg" onload="javascript:if(this.width>screen.width-300)this.width=screen.width-300" border=0><BR><BR>SQL语句为:<BR>CREATE TABLE TEST_CLOB ( ID NUMBER(3), CLOBCOL CLOB)<BR>CREATE TABLE TEST_BLOB ( ID NUMBER(3), BLOBCOL BLOB)<BR><BR></FONT><FONT color=#008000><STRONG>一?CLOB对象的存?BR></STRONG><BR></FONT><FONT color=#008000><STRONG>1、往数据库中插入一个新的CLOB对象<BR></STRONG>public static void clobInsert(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 插入一个空的CLOB对象 */<BR>stmt.executeUpdate("INSERT INTO TEST_CLOB valueS ('111', EMPTY_CLOB())");<BR>/* 查询此CLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 取出此CLOB对象 */<BR>oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");<BR>/* 向CLOB对象中写入数?*/<BR>BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());<BR>BufferedReader in = new BufferedReader(new FileReader(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR><STRONG>2、修改CLOB对象Q是在原CLOB对象基础上进行覆盖式的修改)</STRONG><BR>public static void clobModify(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 查询CLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 获取此CLOB对象 */<BR>oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");<BR>/* q行覆盖式修?*/<BR>BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());<BR>BufferedReader in = new BufferedReader(new FileReader(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>} <BR><BR><STRONG>3、替换CLOB对象Q将原CLOB对象清除Q换成一个全新的CLOB对象Q?/STRONG><BR>public static void clobReplace(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 清空原CLOB对象 */<BR>stmt.executeUpdate("UPDATE TEST_CLOB SET CLOBCOL=EMPTY_CLOB() WHERE ID='111'");<BR>/* 查询CLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 获取此CLOB对象 */<BR>oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");<BR>/* 更新数据 */<BR>BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());<BR>BufferedReader in = new BufferedReader(new FileReader(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR><STRONG>4、CLOB对象d</STRONG><BR>public static void clobRead(String outfile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 查询CLOB对象 */<BR>ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_CLOB WHERE ID='111'");<BR>while (rs.next()) {<BR>/* 获取CLOB对象 */<BR>oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");<BR>/* 以字WŞ式输?*/<BR>BufferedReader in = new BufferedReader(clob.getCharacterStream());<BR>BufferedWriter out = new BufferedWriter(new FileWriter(outfile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>out.close();<BR>in.close();<BR>}<BR>} catch (Exception ex) {<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR><STRONG>二?BLOB对象的存?/STRONG><BR><BR></FONT><FONT color=#008000><STRONG>1?向数据库中插入一个新的BLOB对象<BR></STRONG>public static void blobInsert(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 插入一个空的BLOB对象 */<BR>stmt.executeUpdate("INSERT INTO TEST_BLOB valueS ('222', EMPTY_BLOB())");<BR>/* 查询此BLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 取出此BLOB对象 */<BR>oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");<BR>/* 向BLOB对象中写入数?*/<BR>BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());<BR>BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR><STRONG>2、修改BLOB对象Q是在原BLOB对象基础上进行覆盖式的修改)</STRONG><BR>public static void blobModify(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 查询BLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 取出此BLOB对象 */<BR>oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");<BR>/* 向BLOB对象中写入数?*/<BR>BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());<BR>BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR><STRONG>3、替换BLOB对象Q将原BLOB对象清除Q换成一个全新的BLOB对象Q?/STRONG><BR>public static void blobReplace(String infile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 清空原BLOB对象 */<BR>stmt.executeUpdate("UPDATE TEST_BLOB SET BLOBCOL=EMPTY_BLOB() WHERE ID='222'");<BR>/* 查询此BLOB对象q?*/<BR>ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");<BR>while (rs.next()) {<BR>/* 取出此BLOB对象 */<BR>oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");<BR>/* 向BLOB对象中写入数?*/<BR>BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());<BR>BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR></FONT><FONT color=#008000><STRONG>4、BLOB对象d<BR></STRONG>public static void blobRead(String outfile) throws Exception<BR>{<BR>/* 讑֮不自动提?*/<BR>boolean defaultCommit = conn.getAutoCommit();<BR>conn.setAutoCommit(false);<BR>try {<BR>/* 查询BLOB对象 */<BR>ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222'");<BR>while (rs.next()) {<BR>/* 取出此BLOB对象 */<BR>oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");<BR>/* 以二q制形式输出 */<BR>BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outfile));<BR>BufferedInputStream in = new BufferedInputStream(blob.getBinaryStream());<BR>int c;<BR>while ((c=in.read())!=-1) {<BR>out.write(c);<BR>}<BR>in.close();<BR>out.close();<BR>}<BR>/* 正式提交 */<BR>conn.commit();<BR>} catch (Exception ex) {<BR><BR>/* 出错回滚 */<BR>conn.rollback();<BR>throw ex;<BR>}<BR><BR>/* 恢复原提交状?*/<BR>conn.setAutoCommit(defaultCommit);<BR>}<BR><BR>    观察上述E序对LOBcd字段的存取,我们可以看出Q较之其它类型字D,有下面几个显著不同的特点Q?BR><BR><STRONG>一是必d消自动提交?/STRONG><BR><BR>    存取操作开始前Q必ȝsetAutoCommit(false)取消自动提交。其它类型字D则无此Ҏ要求。这是因为存取LOBcd字段Ӟ通常要进行多ơ操作可以完成。不q样的话QOracle抛出“读取违反顺序”的错误?BR><BR></FONT><FONT color=#008000><STRONG>二是插入方式不同?BR></STRONG><BR>    LOB数据不能象其它类型数据一L接插入(INSERTQ。插入前必须先插入一个空的LOB对象QCLOBcd的空对象为EMPTY_CLOB()QBLOBcd的空对象为EMPTY_BLOB()。之后通过SELECT命o查询得到先前插入的记录ƈ锁定Q而将I对象修改ؓ所要插入的LOB对象?BR><BR><STRONG>三是修改方式不同?/STRONG><BR><BR>    其它cd的字D修ҎQ用UPDATE ?SET…命令即可。而LOBcd字段Q则只能用SELECT ?FOR UPDATE命o记录查询出来ƈ锁定Q然后才能修攏V且修改也有两种ҎQ一是在原数据基上的修改Q即覆盖式修改)Q执行SELECT ?FOR UPDATE后再Ҏ据;二是替换Q先原数据清掉Q再修改Q,先执行UPDATE命oLOB字段之D为空的LOB对象Q然后进行第一U改法。徏议用替换的ҎQ以实现与其它字DUPDATE操作后一L效果?BR><BR><STRONG>四是存取时应使用由数据库JDBC驱动E序提供的LOB操作cR?/STRONG><BR><BR>    对于Oracle数据库,应用oracle.sql.CLOB和oracle.sql.BLOB。不使用由数据库JDBC驱动E序提供的LOBcLQ程序运行时易于出现“抽象方法调用”的错误Q这是因为JDBC所定义的java.sql.Clob与java.sql.Blob接口Q其中的一些方法ƈ未在数据库厂家提供的驱动E序中真正实现?BR><BR><STRONG>五是存取手段与文件操作相ѝ?/STRONG><BR><BR>    对于BLOBcdQ应用InputStream/OutputStreamc,此类不进行编码{换,逐个字节存取。oracle.sql.BLOBcȝ应提供了getBinaryStream()和getBinaryOutputStream()两个ҎQ前一个方法用于读取Oracle的BLOB字段Q后一个方法用于将数据写入Oracle的BLOB字段?BR>    对于CLOBcdQ应用Reader/Writerc,此类q行~码转换。oracle.sql.CLOBcȝ应提供了getCharacterStream()和getCharacterOutputStream()两个ҎQ前一个方法用于读取Oracle的CLOB字段Q后一个方法用于将数据写入Oracle的CLOB字段?BR>    需要说明的是,Z大幅提高E序执行效率Q对BLOB/CLOB字段的读写操作,应该使用~冲操作c(带Buffered前缀Q,卻IBufferedInputStreamQBufferedOutputStreamQBufferedReaderQBufferedWriter。例E中全部使用了缓冲操作类?BR><BR><STRONG>    结Q通过JDBC操纵Oracle数据库的LOB字段Q不外乎插入、修攏V替换、读取四U方式,掌握hq不难。在实际操作中要注意上面所说的几点Q结合阅ME源E序Q用户会很快明白LOBcd字段的用的Q也必将领悟到这U类型字D늚妙处Q?/STRONG></FONT><img src ="http://www.tkk7.com/xiaoxiaoyupku/aggbug/20062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/xiaoxiaoyupku/" target="_blank">潇潇?/a> 2005-11-16 15:04 <a href="http://www.tkk7.com/xiaoxiaoyupku/articles/20062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle数据库中CLOB字段的处理问?http://www.tkk7.com/xiaoxiaoyupku/articles/20053.html潇潇?/dc:creator>潇潇?/author>Wed, 16 Nov 2005 06:35:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/20053.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/20053.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/20053.html#Feedback1http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/20053.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/20053.html
LOBcd分ؓBLOB和CLOB两种QBLOB即二q制大型对象QBinary Large ObjectQ,适用于存贮非文本的字节流数据Q如E序、图象、媄音等Q。而CLOBQ即字符型大型对象(Character Large ObjectQ,则与字符集相养I适于存贮文本型的数据Q如历史档案、大部头著作{)?BR>
对于一般的java应用E序Qclobcd的数据用对象形式插入卛_Q连接方式采用Oracle Thin JDBC Driver
注意Q存取操作开始前Q必ȝsetAutoCommit(false)取消自动提交Q否则Oracle抛出“读取违反顺序”的错误?BR>
取: ...
        con.setAutoCommit(false);
....
        if(rss.next())
        {
          Clob clob = rss.getClob(1);
          if(clob!=null)
   //直接转换为Stringq回Q也可用getCharacterOutputStream()或getAsciiOutputStream()
   //
   String str=clob.getSubString((long) 1, (int) clob.length());
       }
      
写:LOBcd字段Q则只能用SELECT ?FOR UPDATE命o记录查询出来ƈ锁定Q然后才能修?BR>import oracle.sql.CLOB;
OracleResultSet rss=(OracleResultSet)stmt.executeQuery("select my_clob from test where id=1 for update"); 
if(rss.next())
  {
       CLOB clob=(CLOB)rss.getClob(1);
//content为大?k 的String,当然也可使用Ş式写?BR>       clob.putString(1,content);
      .....
      OraclePreparedStatement pstmt=(OraclePreparedStatement)con.prepareStatement("update test set my_clob=?");
      pstmt.setClob(1,(Clob)clob);
        pstmt.executeUpdate();
...
}


但同LҎ在BEA WLS 8.1SP2上取数据没有问题Q写CLOB会有问题的,会报一U这L错误:java.lang.ClassCastException
Ҏbea 是这栯释ƈ解决的:
For most extensions that Oracle provides, you can use the standard technique as described in Using Vendor Extensions to JDBC Interfaces. However, the Oracle Thin driver does not provide public interfaces for its extension methods in the following classes:

oracle.sql.ARRAY
oracle.sql.STRUCT
oracle.sql.REF
oracle.sql.BLOB
oracle.sql.CLOB
WebLogic Server provides its own interfaces to access the extension methods for those classes:

weblogic.jdbc.vendor.oracle.OracleArray
weblogic.jdbc.vendor.oracle.OracleStruct
weblogic.jdbc.vendor.oracle.OracleRef
weblogic.jdbc.vendor.oracle.OracleThinBlob
weblogic.jdbc.vendor.oracle.OracleThinClob

意思即是采用weblogic.jdbc.vendor.oracle.OracleThinClob 替代oracle.sql.CLOB

修改后的写CLOB字段Q只用修改一?其他不变?BR>weblogic.jdbc.vendor.oracle.OracleThinClob  clob=(OracleThinClob)rss.getClob(1);

]]>
SQL Server数据库备份和恢复措施 http://www.tkk7.com/xiaoxiaoyupku/articles/20039.html潇潇?/dc:creator>潇潇?/author>Wed, 16 Nov 2005 04:50:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/20039.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/20039.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/20039.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/20039.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/20039.html一、备份数据库

1、打开SQL企业理器,在控制台根目录中依次点开Microsoft SQL Server
2、SQL Serverl?->双击打开你的服务?->双击打开数据库目?BR>3、选择你的数据库名Uͼ如论坛数据库ForumQ?->然后点上面菜单中的工?->选择备䆾数据?BR>4、备份选项选择完全备䆾Q目的中的备份到如果原来有\径和名称则选中名称点删除,然后Ҏ加,如果原来没有路径和名U则直接选择dQ接着指定路径和文件名Q指定后点确定返回备份窗口,接着点确定进行备?

二、还原数据库

1、打开SQL企业理器,在控制台根目录中依次点开Microsoft SQL Server
2、SQL Serverl?->双击打开你的服务?->点图标栏的新建数据库图标Q新建数据库的名字自行取
3、点L建好的数据库名称Q如论坛数据库ForumQ?->然后点上面菜单中的工?->选择恢复数据?BR>4、在弹出来的H口中的q原选项中选择从设?->炚w择讑֤-->Ҏ?->然后选择你的备䆾文g?->d后点定q回Q这时候设备栏应该出现您刚才选择的数据库备䆾文g名,备䆾号默认ؓ1Q如果您对同一个文件做q多ơ备份,可以点击备䆾h边的查看内容Q在复选框中选择最新的一ơ备份后点确定)-->然后点击上方常规旁边的选项按钮
5、在出现的窗口中选择在现有数据库上强制还原,以及在恢复完成状态中选择使数据库可以l箋q行但无法还原其它事务日志的选项。在H口的中间部位的数据库文gq原里要按照你SQL的安装进行设|(也可以指定自q目录Q,逻辑文g名不需要改动,U至物理文g名要Ҏ你所恢复的机器情况做改动Q如您的SQL数据库装在D:\Program Files\Microsoft SQL Server\MSSQL\DataQ那么就按照您恢复机器的目录q行相关改动改动Qƈ且最后的文g名最好改成您当前的数据库名(如原来是bbs_data.mdfQ现在的数据库是forumQ就Ҏforum_data.mdfQ,日志和数据文仉要按照这L方式做相关的改动Q日志的文g名是*_log.ldfl尾的)Q这里的恢复目录您可以自p|,前提是该目录必须存在Q如您可以指定d:\sqldata\bbs_data.mdf或者d:\sqldata\bbs_log.ldfQ,否则恢复报?BR>6、修改完成后Q点M面的定q行恢复Q这时会出现一个进度条Q提C恢复的q度Q恢复完成后pȝ会自动提C成功,如中间提C报错,误录下相关的错误内容ƈ询问对SQL操作比较熟悉的h员,一般的错误无非是目录错误或者文件名重复或者文件名错误或者空间不够或者数据库正在使用中的错误Q数据库正在使用的错误您可以试关闭所有关于SQLH口然后重新打开q行恢复操作Q如果还提示正在使用的错误可以将SQL服务停止然后重v看看Q至于上q其它的错误一般都能按照错误内容做相应改动后即可恢?BR>

三、收~数据库

    一般情况下QSQL数据库的收羃q不能很大程度上减小数据库大,其主要作用是收羃日志大小Q应当定期进行此操作以免数据库日志过?/P>

1、设|数据库模式为简单模式:打开SQL企业理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Serverl?->双击打开你的服务?->双击打开数据库目?->选择你的数据库名Uͼ如论坛数据库ForumQ?->然后点击右键选择属?->选择选项-->在故障还原的模式中选择“简单”,然后按确定保?BR>2、在当前数据库上点右键,看所有Q务中的收~数据库Q一般里面的默认讄不用调整Q直接点定
3?STRONG>收羃数据库完成后Q徏议将您的数据库属性重新设|ؓ标准模式Q操作方法同W一点,因ؓ日志在一些异常情况下往往是恢复数据库的重要依?

四、设定每日自动备份数据库

    强烈有条件的用户q行此操作!

1、打开企业理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Serverl?->双击打开你的服务?BR>2、然后点上面菜单中的工具-->选择数据库维护计划器
3、下一步选择要进行自动备份的数据-->下一步更新数据优化信息,q里一般不用做选择-->下一步检查数据完整性,也一般不选择
4、下一步指定数据库l护计划Q默认的?周备份一ơ,点击更改选择每天备䆾后点定
5、下一步指定备份的盘目录Q选择指定目录Q如您可以在D盘新Z个目录如Qd:\databakQ然后在q里选择使用此目录,如果您的数据库比较多最好选择为每个数据库建立子目录,然后选择删除早于多少天前的备份,一般设?Q?天,q看您的具体备䆾要求Q备份文件扩展名一般都是bakq默认?BR>6、下一步指定事务日志备份计划,看您的需要做选择-->下一步要生成的报表,一般不做选择-->下一步维护计划历史记录,最好用默认的选项-->下一步完?BR>7、完成后pȝ很可能会提示Sql Server Agent服务未启动,先点定完成计划讑֮Q然后找到桌面最双状态栏中的SQLl色图标Q双ȝ开Q在服务中选择Sql Server AgentQ然后点击运行箭_选上下方的当启动OS时自动启动服?BR>8、这个时候数据库计划已经成功的运行了Q他按照您上面的设|进行自动备?

修改计划Q?/STRONG>

    打开企业理器,在控制台根目录中依次点开Microsoft SQL Server-->SQL Serverl?->双击打开你的服务?->理-->数据库维护计?->打开后可看到你设定的计划Q可以进行修Ҏ者删除操?

五、数据的转移Q新建数据库或{UL务器Q?/B>

    一般情况下Q最好用备份和q原操作来进行{UL据,在特D情况下Q可以用导入导出的方式进行{U,q里介绍的就是导入导出方式,导入导出方式转移数据一个作用就是可以在收羃数据库无效的情况下用来减(收羃Q数据库的大,本操作默认ؓ您对SQL的操作有一定的了解Q如果对其中的部分操作不理解Q可以咨询动|相关h员或者查询网上资?/P>

1、将原数据库的所有表、存储过E导出成一个SQL文gQ导出的时候注意在选项中选择~写索引脚本和编写主键、外键、默认值和查约束脚本选项
2、新建数据库Q对新徏数据库执行第一步中所建立的SQL文g
3、用SQL的导入导出方式,Ҏ数据库导入原数据库中的所有表内容 

                                                                                                      出处Q?A >蓝色理想       责Q~辑Q?A target=_blank>冰点的冰蓝色



]]>
谈jdbcq接sql server2000数据??http://www.tkk7.com/xiaoxiaoyupku/articles/19762.html潇潇?/dc:creator>潇潇?/author>Mon, 14 Nov 2005 12:45:00 GMThttp://www.tkk7.com/xiaoxiaoyupku/articles/19762.htmlhttp://www.tkk7.com/xiaoxiaoyupku/comments/19762.htmlhttp://www.tkk7.com/xiaoxiaoyupku/articles/19762.html#Feedback0http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/19762.htmlhttp://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/19762.html前提Q?BR>     1.sql server 2000 L版本    //本h用的是个人版
      2.sql server 2000 sp3升?BR>          你可以在q里下蝲
http://www.bossed.com.cn/download/detailcp.asp?id=74
      3.sql server 2000 jdbc 驱动  //q个需要自己找?
      4.jdk1.4                      //以下的例子是该版?BR>在以上条件满的情况?作以下事?BR>      1.建立新数据库名ؓQTESTDB ,q在其中建立一个名为test_student的表
          包括以下几列QSnoQSnameQSageQSsexQSclassQ?nbsp; 
      2.开始编写你自己的连接数据库的类Q我q里是借鉴他h的版权不归我所有)Q你也可以用自己的方?nbsp;
class Testj{
    public static void main(String args[])
    {  
        String RL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TESTDB";
        String user ="king";//q里替换成你自已的数据库用户?BR>        String password = "sql";//q里替换成你自已的数据库用户密码
        String sqlStr = "select * from test_student";

        try{    //q里的异常处理语句是必需?否则不能通过~译!    
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            System.out.println( "cd例化成功!" );
            System.out.println("slkdjf");
            Connection con = DriverManager.getConnection(RL,user,password);
            System.out.println( "创徏q接对像成功!" );

            Statement st = con.createStatement();
            System.out.println( "创徏Statement成功!" );

            ResultSet rs = st.executeQuery( sqlStr );
            System.out.println( "操作数据表成?" );
            System.out.println( "----------------!" );

            while(rs.next())
            {
                System.out.print(rs.getInt("Sno") + "    ");
                System.out.print(rs.getString("Sname") + "    ");
                System.out.print(rs.getInt("Sage") + "    ");
                System.out.print(rs.getString("Ssex") + "    ");
                System.out.println(rs.getString("Sclass"));
            }
            rs.close();
            st.close();
            con.close();
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
    }
}
下面q行调试Q?BR>  javac Testj.java
  java Testj
  如果正确输出应该是:
  cd例化成功!
slkdjf
创徏q接对像成功!
创徏Statement成功!
操作数据表成?
----------------!
2000    刚               21    ?nbsp;   12        
2001    黄               22    ?nbsp;   12        
2002    李娜               20    ?nbsp;   11        
2003    王芳               19    ?nbsp;   null
2004    黄明               22    ?nbsp;   11        
2005    梅兰               21    ?nbsp;   12        
2006    李玉               22    ?nbsp;   15        
2007    李^               32    ?nbsp;   12        

注意Q这里有几点要说?BR>1.路径问题Q?BR>  你必配|你的classpath路径否则他在~译时会抱错
  java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:141)
        at Test.main(Test.java:11) 
你的路径应该是这样配|:你可以在在安装jdbc驱动后看那里的帮助文档(是英文的Q;
//q里指在xppȝ?BR> classpath = ,;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
              C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
              C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
  可千万不要写错哟Q?BR> 2.sp3补丁包问题:
    如果你在~译时出C列问?nbsp;那么你需要下载ƈ安装sp3补丁?BR>   java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis
hing socket.
        at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
        at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
        at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
        at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
        at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at Test.main(Test.java:14) 
3.权限问题    
   如果你出现类DL问题
   cd例化成功!
slkdjf
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'king' dp|?BR>原因: 未与信Q SQL Server q接相关联?BR>    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:512)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at Testj.main(Testj.java:14)
    
原困是未讄SQL SERVERd认证模式为؜合认证模式,因ؓSQL SERVER默认安装后认证模式ؓWINDOWS认证模式Q从而导致出错?BR>解决ҎQ启动SQLSERVER企业理器,选择要进行认证模式设|的服务器。右击该服务器,在弹单中选择属性,SQL SERVER?BR>弹出属性对话框在属性对话框中选择安全性选项Q在w䆾验证处选择“SQL Server和Windows”,然后定?/FONT>



]]>
JSP中tomcat的SQL Server2000数据库连接池的配|?/title><link>http://www.tkk7.com/xiaoxiaoyupku/articles/19757.html</link><dc:creator>潇潇?/dc:creator><author>潇潇?/author><pubDate>Mon, 14 Nov 2005 11:34:00 GMT</pubDate><guid>http://www.tkk7.com/xiaoxiaoyupku/articles/19757.html</guid><wfw:comment>http://www.tkk7.com/xiaoxiaoyupku/comments/19757.html</wfw:comment><comments>http://www.tkk7.com/xiaoxiaoyupku/articles/19757.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/xiaoxiaoyupku/comments/commentRss/19757.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/xiaoxiaoyupku/services/trackbacks/19757.html</trackback:ping><description><![CDATA[转蝲Q{载请保留本信息,本文来自<A >http://www.matrix.org.cn/resource/article/1/1357.html</A> <div class="wiw8s4w" id=divarticlecontent>环境Q?BR>1. 数据库:Microsoft SQL Server 2000<BR>2. 数据库驱动程序:net.sourceforge.jtds.jdbc.Driver<BR><BR>JNDIQJava Naming and Directory InterfaceQ概qͼ<BR>Tomcat4Q?Q提供了一个与Java Enterprise Edition应用服务相兼容的JNDI--InitialContext实现实例。它的初始数据设|在$CATALINA_HOME/conf/server.xml文g里,q可能在|页应用环境描述Q?WEB-INF/web.xmlQ里被下列元素引用:<BR>1) <env-entry>--环境入口Q设|应用程序如何操作?BR>2) <resource-ref>--资源参数Q一般是数据库驱动程序、JavaMail Session、自定义cd厂等?BR>3) <resource-env-ref>--在Servlet 2.4里用来简化设|不需认证信息的资源资源如环境参数、resource-ref变量?BR><BR>InitialContext在网应用程序初始化时被讄Q用来支持网应用程序组件。所有的入口和资源都攑֜JNDI命名I间里的java:comp/envD里。点M列网址以获取更多信息:<BR>1) Java命名和目录接口(Java Naming and Directory InterfaceQ?BR>2) J2EEq_说明QJ2EE Platform SpecificationQ?BR><BR>讄JNDI资源<BR>讄JNDI资源要在$CATALINA_HOME/conf/server.xml文g里用下列标志符Q?BR>1) <Environment>--讄域个可变的JNDI InitialContext入口的名字和|同上面说?lt;env-entry>{hQ?BR>2) <Resource>--讄应用E序可用的资源的名字和类型(同上面说?lt;resource-ref>{hQ?BR>3) <ResourceParams>--讄Java资源cd厂的名称或将用的JavaBean属性?BR>4) <ResourceLink>--l全局JNDI环境QJNDI ContextQ添加一个链接?BR>上述q些标志W必L?lt;Context>?lt;/Context>之间Q针对专门的|页应用E序Q或<DefaultContext>?lt;/DefaultContext>之间?BR>此外Q设在网应用环境描qͼWeb Application DescriptorQ(/WEB-INF/web.xmlQ里的名字和g在初始环境(Initial ContextQ里被设|,当被<Environemt>元素值允许时被重设初始倹{?BR>全局变量能在<Server>子元素的<GlobalNamingResources>里设|?BR><BR>数据库连接池概述Q?BR>数据库连接是一U关键的有限的昂늚资源Q这一点在多用L|页应用E序中体现得ؓH出。对数据库连接的理能显著媄响到整个应用E序的׾~性和健壮性,影响到程序的性能指标。数据库q接池正是针对这个问题提出来的?BR>数据库连接池负责分配、管理和释放数据库连接,它允许应用程序重复用一个现有的数据库连接,而再不是重新建立一个;释放I闲旉过最大空闲时间的数据库连接来避免因ؓ没有释放数据库连接而引L数据库连接遗漏。这Ҏ术能明显提高Ҏ据库操作的性能?BR>数据库连接池在初始化时将创徏一定数量的数据库连接放到连接池中,q些数据库连接的数量是由最数据库q接数来讑֮的。无些数据库q接是否被用,q接池都一直保证至拥有这么多的连接数量。连接池的最大数据库q接数量限定了这个连接池能占有的最大连接数Q当应用E序向连接池h的连接数过最大连接数量时Q这些请求将被加入到{待队列中。数据库q接池的最连接数和最大连接数的设|要考虑C列几个因素:<BR>1) 最连接数是连接池一直保持的数据库连接,所以如果应用程序对数据库连接的使用量不大,会有大量的数据库连接资源被费Q?BR>2) 最大连接数是连接池能申L最大连接数Q如果数据库q接h过此数Q后面的数据库连接请求将被加入到{待队列中,q会影响之后的数据库操作?BR>3) 如果最连接数与最大连接数相差太大Q那么最先的q接h会获利Q之后超q最连接数量的q接h{h于徏立一个新的数据库q接。不q,q些大于最连接数的数据库q接在用完不会马上被释放,它将被放到连接池中等待重复用或是空闲超时后被释放?BR><BR>配置Tomcat数据库连接池的前提:<BR>1. 必须装有Javaq行环境Q?BR>2. 必须有SQL Server2000数据库服务器Q可以不在本圎ͼQ?BR>3. 必须有jtds.jarQƈ它攑֜$CATALINA_HOME/common/lib目录下(只能是这里)。用它是因为Microsoft公司的Java SQL Server驱动E序不支持二ơ查询,可到|上搜到。目前用的是jtds-0.6.jar?BR><BR>?CATALINA_HOME/conf/server.xml里设|数据库q接池:<BR>下面是配|的代码Q必L?lt;Host>?lt;/Host>之间?BR><PRE class=overflow title="pre code"><Context path="/quality" docBase="quality" debug="0" reloadable="true" crossContext="true"><BR><Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_quality_log." suffix=".txt" timestamp="true"/><BR><Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"/><BR><ResourceParams name="jdbc/connectDB"><BR> <parameter><BR>  <name>maxActive</name><BR>  <!-- Maximum number of DB connections in pool.Set to 0 for no limit. --><BR>  <value>100</value><BR> </parameter><BR> <parameter><BR>  <name>maxIdle</name><BR>  <!-- Maximum number of idle DB connections to retain in pool.Set to 0 for no limit. --><BR>  <value>30</value><BR> </parameter><BR> <parameter><BR>  <name>maxWait</name><BR>  <!-- Maximum time to wait for a DB connection to become available in ms.An exception is thrown if this timeout is exceeded.Set to -1 to wait indefinitely. --><BR>  <value>10000</value><BR> </parameter><BR> <parameter><BR>  <name>removeAbandoned</name><BR>  <!-- Abandoned DB connections are removed and recycled --><BR>  <value>true</value><BR> </parameter><BR> <parameter><BR>  <name>removeAbandonedTimeout</name><BR>  <!-- Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned.  --><BR>  <value>60</value><BR> </parameter><BR> <parameter><BR>  <name>logAbandoned</name><BR>  <!-- Log a stack trace of the code which abandoned --><BR>  <value>false</value><BR> </parameter><BR> <parameter><BR>  <name>factory</name><BR>  <!-DBCP Basic Datasource Factory --><BR>  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value><BR> </parameter><BR> <parameter><BR>  <name>username</name><BR>  <!-- Database User Name --><BR>  <value>Iorishinier</value><BR> </parameter><BR> <parameter><BR>  <name>password</name><BR>  <!-- User Password --><BR>  <value>mypasswd</value><BR> </parameter><BR> <parameter><BR>  <name>driverClassName</name><BR>  <!-- Database Driver Class Name --><BR>  <value>net.sourceforge.jtds.jdbc.Driver</value><BR> </parameter><BR> <parameter><BR>  <name>url</name><BR>  <!-- Database Address --><BR>  <value>jdbc:jtds:sqlserver://127.127.127.127:1433/Northwind</value><BR> </parameter><BR></ResourceParams><BR></Context></PRE><BR>下面是一些参数的说明Q?BR><Context path="/quality" docBase="quality" debug="0" reloadable="true" crossContext="true"><BR>其中Q?BR>1) path 指定路径Q这里设定的?CATALINA_HOME/webapps下的quality目录Q?BR>2) docBase 文g根目录?BR>3) reloader 当网被更新时是否重新编译?BR>4) maxActive q接池的最大数据库q接数。设?表示无限制?BR>5) maxIdle 数据库连接的最大空闲时间。超q此I闲旉Q数据库q接被标记Z可用Q然后被释放。设?表示无限制?BR>6) maxWait 最大徏立连接等待时间。如果超q此旉接到异常。设为-1表示无限制?BR>7) removeAbandoned 回收被遗弃的Q一般是忘了释放的)数据库连接到q接池中?BR>8) removeAbandonedTimeout 数据库连接过多长旉不用被视ؓ被遗弃而收回连接池中?BR>9) logAbandoned 被遗弃的数据库q接的回收记入日志?BR>10) driverClassName JDBC驱动E序?BR>11) url 数据库连接字W串<BR><BR>?CATALINA_HOME/webapps/quality/WEB-INF/web.xml里设|被引用的资源:<BR>下面是配|代码,必须攑֜<web-app>?lt;/web-app>里?BR><PRE class=overflow title="pre code"><!-- Database Config start --><BR><resource-ref><BR><description>connectDB test</description><BR><res-ref-name>jdbc/connectDB</res-ref-name><BR><res-type>javax.sql.DataSource</res-type><BR><res-auth>Container</res-auth><BR></resource-ref><BR><!-- Database Config end --></PRE><BR><BR>下面是一下参数的必要说明Q?BR>1) description 对被引用的资源的描述?BR>2) res-ref-name 资源名称。见上面?lt;ResourceParams name="jdbc/connectDB"><BR>3) res-type 资源cd。见上面?lt;Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"/><BR><BR>在JSP中用资源:<BR>q是?CATALINA_HOME/webapps/quality下的某子目录里的jsp|页文g部分代码Q?BR><PRE class=overflow title="pre code"><%@ page contentType="text/html;charset=GBK"%><BR><%@ page errorPage="error.jsp"%><BR><%@ page import="javax.naming.*"%><BR><%@ page import="javax.sql.*"%><BR><%@ page import="java.sql.*"%><BR><html><BR> <head><BR> </head><BR> <body><BR>  <%<BR><BR>   ……………?BR>   ……………?BR><BR>   // 数据库操?BR>   Context ctx=null;<BR>   Connection cnn=null;<BR>   Statement stmt=null;<BR>   ResultSet rs=null;<BR>   try<BR>   {<BR>    ctx=new InitialContext();<BR>    if(ctx==null)<BR>     throw new Exception("没有匚w的环?);<BR>    DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");<BR>    if(ds==null)<BR>     throw new Exception("没有匚w数据?);<BR>    <BR>    cnn=ds.getConnection();<BR>    stmt=cnn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);<BR>    rs=stmt.executeQuery("select * from table1");<BR><BR>    ……………?BR>    ……………?BR><BR>   }<BR>   finally<BR>   {<BR>    if(rs!=null)<BR>     rs.close();<BR>    if(stmt!=null)<BR>     stmt.close();<BR>    if(cnn!=null)<BR>     cnn.close();<BR>    if(ctx!=null)<BR>     ctx.close();<BR>   }<BR>    %><BR> </body><BR></html></PRE><BR><BR>代码说明Q?BR>DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");<BR>上面q句应用了刚才设的资源?BR>资源使用完要释放Q尤其是Context资源Q见try-catch-finally部分的finally代码D,q是一U好的习惯。资源释放时如果释放了上U资源,下资源先被释放。如Q释放了ctxQ那么资源释N序将是rsQstmtQcnnQctx。换句话_如果释放了ctxQ那么rsQstmt和cnn都将不可用了?BR>q里的释放资源只是将数据库连接返回连接池中,q不是把资源真正释放掉,见数据库q接池概q?BR></DIV><img src ="http://www.tkk7.com/xiaoxiaoyupku/aggbug/19757.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/xiaoxiaoyupku/" target="_blank">潇潇?/a> 2005-11-14 19:34 <a href="http://www.tkk7.com/xiaoxiaoyupku/articles/19757.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://pite2.com" target="_blank">һ˿wwwѸĻ</a>| <a href="http://yakonet.com" target="_blank">Ļ߹ۿƬ</a>| <a href="http://sznsfe.com" target="_blank">һëƬ߲ </a>| <a href="http://helloyp.com" target="_blank">91Ƶ</a>| <a href="http://zzz134.com" target="_blank">޾ƷŮ߹ۿ</a>| <a href="http://gttest5.com" target="_blank">ձƬѹۿ</a>| <a href="http://lswqn.com" target="_blank">ȫ߹ۿѹۿȫ </a>| <a href="http://c4665.com" target="_blank">avɫӰ</a>| <a href="http://dd5566.com" target="_blank">߹ۿAVƬ</a>| <a href="http://shandonghj.com" target="_blank">һ˿wwwƵ߹ۿ һ˿ѹۿձƵwww </a>| <a href="http://aabbcc567.com" target="_blank">ݺݺݰƵ</a>| <a href="http://zhxydq.com" target="_blank">޼ɫС˵</a>| <a href="http://010youhua.com" target="_blank">޳avƬþ</a>| <a href="http://8222se.com" target="_blank">޹Ʒһ</a>| <a href="http://hwafarda.com" target="_blank">ĻmvѸƵ8</a>| <a href="http://ss8kk.com" target="_blank">޾ƷƬ</a>| <a href="http://juytv.com" target="_blank">aëƬƵ</a>| <a href="http://77133144.com" target="_blank">һAëƬѹۿþþƷ </a>| <a href="http://selangcun.com" target="_blank">99reѾƷƵۿ</a>| <a href="http://3589006.com" target="_blank">ŮҰbbwbbw</a>| <a href="http://bovch.com" target="_blank">ĻۺСۺ</a>| <a href="http://789xxoo.com" target="_blank">4huĻѵַ</a>| <a href="http://shiliuvip.com" target="_blank">˺Ů˸߳վ</a>| <a href="http://czxgjt.com" target="_blank">˾þô߽ڹ</a>| <a href="http://watchmini.com" target="_blank">һ߲ѹۿİƵ </a>| <a href="http://avdian126.com" target="_blank">ۺϾƷվ</a>| <a href="http://www-070755.com" target="_blank">˿wwwƵ</a>| <a href="http://gz-shunan.com" target="_blank">AVþþþվ</a>| <a href="http://udlmw.com" target="_blank">һɫþۺ޾Ʒ</a>| <a href="http://kyqp0022.com" target="_blank">ѻɫַվ</a>| <a href="http://sjkuaixun.com" target="_blank">aaëƬëƬѹۿ</a>| <a href="http://140699.com" target="_blank">˳ɵӰվ</a>| <a href="http://www-959kj.com" target="_blank">Ʒa߹ۿ</a>| <a href="http://020iws.com" target="_blank">ĻƵ</a>| <a href="http://31xyz.com" target="_blank">߾ƷƵ</a>| <a href="http://zblinghang.com" target="_blank">91Ƶѹۿ</a>| <a href="http://d8139.com" target="_blank">߾Ʒۿѹۿ</a>| <a href="http://yjjinfeng.com" target="_blank">WWWɫ.COM </a>| <a href="http://hysw100.com" target="_blank">av߲ </a>| <a href="http://chaikexin.com" target="_blank">þþù޾Ʒ</a>| <a href="http://www-554757.com" target="_blank">þ޾ƷĻ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>