表示預(yù)編譯的 SQL 語句的對象。 SQL 語句被預(yù)編譯并且存儲在
<CODE>PreparedStatement</CODE> 對象中。然后可以使用此對象高效地多次執(zhí)行該語句</P>
A: 關(guān)于XML和HTML區(qū)別請參考:
“可擴展標(biāo)記語言”(XML) 提供一種描述結(jié)構(gòu)化數(shù)據(jù)的方法。與主要用于控制數(shù)據(jù)的顯示和外觀的 HTML 標(biāo)記不同,XML 標(biāo)記用于定義數(shù)據(jù)本身的結(jié)構(gòu)和數(shù)據(jù)類型。
XML 使用一組標(biāo)記來描繪數(shù)據(jù)元素。每個元素封裝可能十分簡單也可能十分復(fù)雜的數(shù)據(jù)。您可以定義一組無限制的 XML 標(biāo)記。例如,您可以定義一些 XML 標(biāo)記來聲明訂單中的數(shù)據(jù),如價格、稅收、發(fā)貨地址、帳單地址等等。由于 XML 標(biāo)記在整個單位中以及跨單位采用,因此來自各種不同數(shù)據(jù)存儲區(qū)的數(shù)據(jù)將更容易交換和操作。
XML 是一種簡單、與平臺無關(guān)并被廣泛采用的標(biāo)準。XML 相對于 HTML 的優(yōu)點是它將用戶界面與結(jié)構(gòu)化數(shù)據(jù)分隔開來。這種數(shù)據(jù)與顯示的分離使得集成來自不同源的數(shù)據(jù)成為可能。客戶信息、訂單、研究結(jié)果、帳單付款、病歷、目錄數(shù)據(jù)及其他信息都可以轉(zhuǎn)換為 XML。
XML 與 HTML
以下是要記住的有關(guān) XML 與 HTML 之間關(guān)系的幾個要點:
a.. XML 不是要替換 HTML;實際上 XML 可以視作對 HTML 的補充。XML 和 HTML 的目標(biāo)不同:HTML 的設(shè)計目標(biāo)是顯示數(shù)據(jù)并集中于數(shù)據(jù)外觀,而 XML 的設(shè)計目標(biāo)是描述數(shù)據(jù)并集中于數(shù)據(jù)的內(nèi)容。
b.. 與 HTML 相似,XML 不進行任何操作。雖然 XML 標(biāo)記可用于描述訂單之類的項的結(jié)構(gòu),但它不包含可用于發(fā)送或處理該訂單以及確保按該訂單交貨的任何代碼。其他人必須編寫代碼來實際對 XML 格式的數(shù)據(jù)執(zhí)行這些操作。
c.. 與 HTML 不同,XML 標(biāo)記由架構(gòu)或文檔的作者定義,并且是無限制的。HTML 標(biāo)記則是預(yù)定義的;HTML 作者只能使用當(dāng)前 HTML 標(biāo)準所支持的標(biāo)記。
XML 的使用
XML 是一種極靈活的、傳遞數(shù)據(jù)的方式。以下全部是可使用 XML 的場合的示例:
a.. 普通文檔
b.. 結(jié)構(gòu)化記錄,如約會記錄或訂單
c.. 移動數(shù)據(jù)的 Internet/Intranet Web 應(yīng)用程序
d.. 帶有數(shù)據(jù)的對象,如對象或 ActiveX 控件的持久格式
e.. 數(shù)據(jù)記錄,如查詢的結(jié)果集
f.. Web 站點的元內(nèi)容,如“信道定義格式”(CDF)
g.. 圖形顯示,如應(yīng)用程序的用戶界面
h.. Web 上信息與人的鏈接
i.. C# 代碼(可以用 XML 形式);有關(guān)更多信息,請參見 XML 文檔
j.. 用于定位可用 XML Web services 的發(fā)現(xiàn)文檔;有關(guān)更多信息,請參見 XML Web services 發(fā)現(xiàn)。
以下列出存儲信息時 XML 相對于其他格式的若干優(yōu)越性:
a.. XML 格式是基于文本的,這使得它們更容易讀、更便于記錄,有時也更便于調(diào)試。
b.. XML 文檔可使用已為 HTML 建立的很多基礎(chǔ)結(jié)構(gòu),包括 HTTP 協(xié)議和某些瀏覽器。HTTP 允許穿過防火墻傳輸 XML。
c.. XML 分析已有完善的定義,且已廣泛應(yīng)用,使得在各種環(huán)境中從 XML 文檔檢索信息成為可能。
d.. 應(yīng)用程序可依賴 XML 分析器進行某些結(jié)構(gòu)驗證以及數(shù)據(jù)類型檢查(當(dāng)使用架構(gòu)時)。
e.. XML 建立在 Unicode 基礎(chǔ)上,使得創(chuàng)建國際化文檔更容易。不過,XML 并不適合于所有情況。XML 文檔往往比它們替換的二進制格式詳細。它們占用更多的網(wǎng)絡(luò)帶寬和存儲空間,或需要更多的處理器時間進行壓縮。XML 分析可能比分析高度優(yōu)化的二進制格式慢,并且可能需要更多內(nèi)存。然而,精心的應(yīng)用程序設(shè)計能夠
避免一些問題。
驗證 XML 文檔
若要驗證 XML 文檔包含所需數(shù)據(jù)和結(jié)構(gòu),必須將一個 XML 架構(gòu)與 XML 文檔相關(guān)聯(lián)。XML 架構(gòu)是定義如何構(gòu)造元素和屬性來形成 XML 文檔的規(guī)則。您可以在單位之間共享架構(gòu),以使得傳輸和處理共享數(shù)據(jù)變得簡單。有關(guān)更多信息,請參見 XML 架構(gòu)介紹。
顯示 XML 數(shù)據(jù)
有幾種方式可用于顯示(或提供)XML 數(shù)據(jù)。
還有數(shù)據(jù)綁定的機制可與樣式表一起使用,以便以可視形式展示 XML 數(shù)據(jù),以及添加交互性。
以下是顯示 XML 的幾種方法:
a.. XSLT — 可擴展樣式表語言
b.. CSS — 級聯(lián)樣式表
c.. Microsoft Internet Explorer
有關(guān)更多信息,請參見 MSDN Online XML 開發(fā)人員中心 Web 站點
(http://msdn.microsoft.com/xml/default.asp)。
XML 資源
如果您熟悉 HTML,則可以學(xué)習(xí)創(chuàng)建 XML 文檔,只要求它們有效且符合標(biāo)準格式。有關(guān)
XML 的更多信息,請參見 XML SDK 和 MSDN Online XML 開發(fā)人員中心 Web 站點
(http://msdn.microsoft.com/xml/default.asp)。
摘自:http://www.5217.cn/Article/jzjc/wzjss/htmljs/200503/234.html
鎖有兩種:悲觀鎖和樂觀鎖。悲觀鎖假定其他用戶企圖訪問或者改變你正在訪問、更改的對象的概率是很高的,因此在悲觀鎖的環(huán)境中,在你開始改變此對象之前就將該對象鎖住,并且直到你提交了所作的更改之后才釋放鎖。悲觀的缺陷是不論是頁鎖還是行鎖,加鎖的時間可能會很長,這樣可能會長時間的限制其他用戶的訪問,也就是說悲觀鎖的并發(fā)訪問性不好。與悲觀鎖相反,樂觀鎖則認為其他用戶企圖改變你正在更改的對象的概率是很小的,因此樂觀鎖直到你準備提交所作的更改時才將對象鎖住,當(dāng)你讀取以及改變該對象時并不加鎖。可見樂觀鎖加鎖的時間要比悲觀鎖短,樂觀鎖可以用較大的鎖粒度獲得較好的并發(fā)訪問性能。但是如果第二個用戶恰好在第一個用戶提交更改之前讀取了該對象,那么當(dāng)他完成了自己的更改進行提交時,數(shù)據(jù)庫就會發(fā)現(xiàn)該對象已經(jīng)變化了,這樣,第二個用戶不得不重新讀取該對象并作出更改。這說明在樂觀鎖環(huán)境中,會增加并發(fā)用戶讀取對象的次數(shù)。
Synchronized method - By using this, the method will be thread safe. But if your
method access any non-thread safe objects, you may have concurrency problem.
Synchronized block - To complement what Synchronized method cannot do.
If you do:
synchronized (nonThreadSafeObject) {
// accessing
nonThreadSafeObject here
}
Then the object will become thread safe.
Passivation and activation are two
phases of a resource management technique that reduces the number of bean
instances needed to service all clients. Passivation is the process of
disassociating a bean instance from its EJB object so that the instance can be
reused or evicted to conserve memory. Activation is the process of associating a
bean instance with an EJB object so that it can service a request. Beans are
passivated when there is a lull in their use and activated when the EJB object
receives a client request.
The java.ejb.SessionBean and javax.ejb.EntityBean interface
include two callback methods that notify a bean instance when it is about to
passivated or activated. The ejbPassivate( ) method notifies a bean
that it is about to passivated; the ejbActivate( ) method notifies a
bean that it is about to activated.
The mechanisms employed in passivation and activation change depending on the
bean type. Stateful beans are usually evicted, while entity beans and stateless
beans are pooled. A more detailed account of how different bean types passivated
and activated is found under the FAQs for that type.
Transaction Isolation Levels
Overview
The ANSI/ISO SQL standard defines four levels of transaction isolation in terms of three potential problems that must be prevented between concurrent transactions. These problems are:
-
Dirty Read - A transaction reads data written by another concurrent uncommitted transaction.
-
Non-Repeatable Reads - A transaction re-reads data it has previously read and finds that data has been modified by another transaction (one that has been committed since the transaction's previous read).
-
Phantom Read - A transaction re-executes a query returning a set of rows that satisfy a search condition and finds that the set of rows satisfying the condition has changed due to another recently-committed transaction.
Transaction Isolation Levels
The four levels of transaction isolation are:
-
Uncommitted Read
-
Committed Read
-
Repeatable Read
-
Serializable.
The isolation level that your transaction runs in determines how sensitive your application is to changes other users' transactions make, and consequently, how long your transaction must hold locks to protect against these changes. The ANSI SQL standard defines four levels of transaction isolation.
Uncommitted Read
Uncommitted Read, or dirty read, lets a transaction read any data currently on a data page, regardless of whether or not the data has been committed. For example, another user might have a transaction in progress that has updated data, and that transaction is holding exclusive locks on the data. Your transaction can read the data anyway, and possibly take further actions based on the values you read. The other user might then decide to roll back their transaction, so logically, those changes never occurred.
Committed Read
Committed Read ensures that an operation will never read data another application has changed but not yet committed. Because you can never read uncommitted data, if a transaction running with Committed Read isolation revisits data, that data might have changed, or new rows might appear that meet the criteria of the original query. Rows that appear in this way are called phantoms.
Repeatable Read
If you want the read operations to be repeatable, choose the third isolation level. The Repeatable Read isolation level adds to the properties of Committed Read by ensuring that if a transaction revisits data or if a query is reissued, the data will not have changed. In other words, issuing the same query twice within a transaction will not pick up any changes to data values that another user's transaction has made. No other user can modify the data that your transaction visits as long as you have not yet committed or rolled back your transaction.
Serializable
The Serializable isolation level ensures that if a query is reissued, no data will have changed and no new rows will appear in the interim. In other words, you will not see phantoms if the same query is issued twice within a transaction.
Transaction isolation Levels Behavior
The four transaction isolation levels and the corresponding behaviors are described below:
Isolation Level
|
Dirty Read
|
Non-Repeatable Read
|
Phantom Read
|
Read Uncommitted
|
Possible
|
Possible
|
Possible
|
Read Committed
|
Not possible
|
Possible
|
Possible
|
Repeatable Read
|
Not possible
|
Not possible
|
Possible
|
Serializable
|
Not possible
|
Not possible
|
Not possible
|
Support for Transaction Isolation Levels in Orbix E2A Application Server
With Orbix E2A Application Server, you can specify the transaction isolation level for an entire EJB in an application's cc.xml file by setting the new <connection-tx-isolation-level> element in the relevant <resource-ref> and <cmp-datasource> elements.
The valid values for the <connection-tx-isolation-level> element are:
-
TRANSACTION_READ_UNCOMMITTED
-
TRANSACTION_READ_COMMITTED
-
TRANSACTION_REPEATABLE_READ
-
TRANSACTION_SERIALIZABLE
The following is an extract of a cc.xml file using transaction isolation levels for the Account and Person demos that ship with Orbix E2A Application Server.
|
<configuration>
<enterprise-beans>
<entity>
<ejb-name>Account</ejb-name>
<jndi-name>iona/ipas/simple/Account</jndi-name>
<jndi-source-name>CosNaming</jndi-source-name>
<resource-ref>
<res-ref-name>jdbc/Accounts</res-ref-name>
<res-ref-link>JDBCAccounts</res-ref-link>
<connection-tx-isolation-level>TRANSACTION_READ_COMMITTED
</connection-tx-isolation-level>
</resource-ref>
</entity>
<entity>
<ejb-name>Person</ejb-name>
<jndi-name>iona/ipas/simple/Person</jndi-name>
<jndi-source-name>CosNaming</jndi-source-name>
<cmp-datasource>
<res-ref-name>jdbc/Person</res-ref-name>
<res-ref-link>JDBCPerson</res-ref-link>
<connection-tx-isolation-level>TRANSACTION_SERIALIZABLE
</connection-tx-isolation-level>
</cmp-datasource>
...
</entity>
</enterprise-beans>
<resources>
<resource>
<resource-name>JDBCPerson</resource-name>
<jndi-name>iona:cloudscape/demos</jndi-name>
</resource>
<resource>
<resource-name>JDBCAccounts</resource-name>
|
|
<jndi-name>iona:cloudscape/demos</jndi-name>
</resource>
</resources>
...
</configuration>
|
What are Transactions?
A transaction is unit of work containing activities that need to be completed together. For instance, for an online travel site, you might have a session bean method bookTravel that takes a credit card, ensures its valid, charges the price of the ticket on the credit card, and books the ticket. This method invoke methods on other EBJs to help accomplish these steps. For instance, methods of Customer, CreditCard and AirlineTicket beans will be invoked during the execution of this method. If all these steps complete successfully, the transaction succeeds. If any of these steps fails, the entire transaction fails and any changes made by previous steps are rolled back. For instance, if the ticket price is charged on the credit card, but booking the ticket fails, the charge on the credit card must be undone.
If all activities that make up the transaction execute successfully, all changes that were made as part of the transaction are committed. If the transaction fails, these changes are rolled back.
Reliable transactions have the following properties:
http://www.iona.com/support/docs/e2a/asp/5.0/j2ee/DevelopGuide/html/Jta-Bas5.html
定時批處理作業(yè)是J2EE企業(yè)應(yīng)用里很重要的一環(huán),用來在晚間進行財務(wù)掛賬,數(shù)據(jù)轉(zhuǎn)存,新聞聯(lián)播等等操作。
而在Spring里,已經(jīng)很好的集成了Quartz,簡單到像配cron一樣,在xml文件里面配一下時間就可以自動執(zhí)行,不需要寫一行代碼。Spring對Quartz大刀闊斧的簡化堪稱范例,Quartz項目組也許可以學(xué)習(xí)一下。
<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"><ref bean="financeDAO"/></property>
<property name="targetMethod"><value>confirmOrder</value></property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="methodInvokingJobDetail"/>
</property>
<property name="cronExpression">
<value>0 0 6,12,20 * * ?</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list><ref local="cronTrigger"/></list>
</property>
</bean>
上面這段配置文件規(guī)定了在早上6點和晚上8點執(zhí)行financeDAO對象的confirmOrder()方法.
附:cronExpression配置說明
字段 允許值 允許的特殊字符
秒 0-59 , - * /
分 0-59 , - * /
小時 0-23 , - * /
日期 1-31 , - * ? / L W C
月份 1-12 或者 JAN-DEC , - * /
星期 1-7 或者 SUN-SAT , - * ? / L C #
年(可選) 留空, 1970-2099 , - * /
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
“*”字符被用來指定所有的值。如:”*“在分鐘的字段域里表示“每分鐘”。
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.
“?”字符只在日期域和星期域中使用。它被用來指定“非明確的值”。當(dāng)你需要通過在這兩個域中的一個來指定一些東西的時候,它是有用的。看下面的例子你就會明白。
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
“-”字符被用來指定一個范圍。如:“10-12”在小時域意味著“10點、11點、12點”。
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
“,”字符被用來指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”.
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days.
The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month".
The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.
The 'C' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "calendar". This means values are calculated against the associated calendar, if any. If no calendar is associated, then it is equivalent to having an all-inclusive calendar. A value of "5C" in the day-of-month field means "the first day included by the calendar on or after the 5th". A value of "1C" in the day-of-week field means "the first day included by the calendar on or after sunday".
源自:http://www.tkk7.com/javaora/archive/2005/07/20/8070.aspx
最近使用<html:select>標(biāo)簽,下面是我的一點體會:
1. <html:select> 標(biāo)簽一點要嵌套在 <html:form> 標(biāo)簽中使用
2. 必須設(shè)置<html:select>的property屬性,并且屬性的名字要和 YourActionForm 中數(shù)據(jù)成員名相同,且提供getXXX() 和 setXXX() 方法. 提交表單后 property 屬性中存放的就是用戶的選擇項
3. 下拉框用的是鍵/值對的模式,因此建議把數(shù)據(jù)存放在 LabelValueBean 對象中,并把這些對象存放在List中,也方便后續(xù)運用;
4. 在<html:select>標(biāo)簽中運用<html:options>來顯示數(shù)據(jù)
<html:option collection="存放對象的List"
property="value" 對應(yīng)值
LabelProperty="label" 對應(yīng)鍵/>
5. 這樣就可以在頁面中顯示下拉框了
1. 下載"mysql-standard-5.0.27-Linux-i686-icc-glibc23.tar.gz",推薦ICC版本,據(jù)稱比GCC性能提高10-20%
2. 復(fù)制到/usr/local/,解壓:tar zxvf mysql-standard-5.x

.tar.gz
3. 添加用戶和組mysql:
groupadd mysql
useradd -g mysql mysql
4. 創(chuàng)建符號連接:/usr/local # ln -s mysql-standard-5.x

mysql
5. cd mysql,當(dāng)前目錄改為/usr/local/mysql/
6. 運行腳步初始化數(shù)據(jù)庫:./scripts/mysql_install_db --user=mysql
7. 設(shè)置權(quán)限:
/usr/local/mysql # chown -R root .
/usr/local/mysql # chown -R mysql data
/usr/local/mysql # chgrp -R mysql
8. 根據(jù)需要創(chuàng)建并修改/etc/my.cnf,參考配置:
[mysqld]
# 設(shè)置默認為INNODB表,支持事務(wù):
default-storage-engine=INNODB
# 設(shè)置默認的字符集:
default-character-set=utf8
# 禁用bdb:
skip-bdb
9. 啟動MySQL:
/usr/local/mysql/bin # ./mysqld_safe --user=mysql &10. 初始化root口令:
/usr/local/mysql/bin # ./mysqladmin -u root -p password "password-of-root"Enter password: <輸入舊口令,直接按Enter>
11. 以root登錄創(chuàng)建數(shù)據(jù)庫:
/usr/local/mysql # ./mysql -u root -p
Enter password: password-of-root創(chuàng)建一個新用戶:
mysql> create user test identified by 'test-password';創(chuàng)建一個新數(shù)據(jù)庫:
mysql> create database testdb;賦予test用戶從localhost訪問testdb的權(quán)限:
mysql> grant all privileges on testdb.* to
'test'@'localhost';//此處是允許test用戶通過本地訪問數(shù)據(jù)庫,如果想讓test用戶可以在任意地址訪問該數(shù)據(jù)庫可以寫成 grant all privileges on testdb.* to 'test'@'%';
為test 用戶設(shè)定密碼:
1、首先以test用戶登錄到數(shù)據(jù)庫,eg. mysql -utest -p
2、提示輸入密碼時直接回車即可。
3、進入mysql后使用如下命令可以為tes設(shè)定密碼:SET PASSWORD = PASSWORD('biscuit');
停止MySQL服務(wù)器:
/usr/local/mysql/bin # ./mysqladmin -u root -p shutdown
Enter password: password-of-root
STOPPING server from pid file /usr/local/mysql/data/debian.pid
xxx mysqld ended
源自:http://www.linuxdiyf.com/viewarticle.php?id=48495
http://bbs.mysql.cn/thread-1614-1-1.html
http://www.chinaunix.net/jh/17/712043.html
關(guān)于mysql用戶管理,參考:
http://blog.chinaunix.net/u/19185/showart_156037.html