#
用語(yǔ)句設(shè)置sqlserver的信息的語(yǔ)言: set language 'us_english' 上面是把語(yǔ)言設(shè)置成美國(guó)英語(yǔ). set
language 'Simplified Chinese' 上面是把語(yǔ)言設(shè)置成簡(jiǎn)體中文.
安裝了 SQL Server
提供的三十三種語(yǔ)言。下面是語(yǔ)言列表。
用英語(yǔ)表示的名稱 NT LCID SQL Server 消息組 ID English
1033 1033 German 1031 1031 French 1036 1036 Japanese 1041 1041
Danish 1030 1030 Spanish 3082 3082 Italian 1040 1040 Dutch 1043
1043 Norwegian 2068 2068 Portuguese 2070 2070 Finnish 1035 1035
Swedish 1053 1053 Czech 1029 1029 Hungarian 1038 1038 Polish
1045 1045 Romanian 1048 1048 Croatian 1050 1050 Slovak 1051 1051
Slovene 1060 1060 Greek 1032 1032 Bulgarian 1026 1026 Russian
1049 1049 Turkish 1055 1055 British English 2057 1033 Estonian 1061
1061 Latvian 1062 1062 Lithuanian 1063 1063 Brazilian 1046 1046
Traditional Chinese 1028 1028 Korean 1042 1042 Simplified Chinese
2052 2052 Arabic 1025 1025 Thai 1054 1054
CREATE TABLE #test (f_int INT,f_varchar
VARCHAR(255)) 上面創(chuàng)建了一張臨時(shí)表.
臨時(shí)表 SQL Server 支持臨時(shí)表。臨時(shí)表就是那些名稱以井號(hào) (#)
開頭的表。如果當(dāng)用戶斷開連接時(shí)沒有除去臨時(shí)表,SQL Server 將自動(dòng)除去臨時(shí)表。臨時(shí)表不存儲(chǔ)在當(dāng)前數(shù)據(jù)庫(kù)內(nèi),而是存儲(chǔ)在系統(tǒng)數(shù)據(jù)庫(kù) tempdb
內(nèi)。
臨時(shí)表有兩種類型:
本地臨時(shí)表 以一個(gè)井號(hào) (#)
開頭的那些表名。只有在創(chuàng)建本地臨時(shí)表的連接上才能看到這些表。
全局臨時(shí)表 以兩個(gè)井號(hào) (##)
開頭的那些表名。在所有連接上都能看到全局臨時(shí)表。如果在創(chuàng)建全局臨時(shí)表的連接斷開前沒有顯式地除去這些表,那么只要所有其它任務(wù)停止引用它們,這些表即被除去。當(dāng)創(chuàng)建全局臨時(shí)表的連接斷開后,新的任務(wù)不能再引用它們。當(dāng)前的語(yǔ)句一執(zhí)行完,任務(wù)與表之間的關(guān)聯(lián)即被除去;因此通常情況下,只要?jiǎng)?chuàng)建全局臨時(shí)表的連接斷開,全局臨時(shí)表即被除去。
現(xiàn)在,臨時(shí)表的許多傳統(tǒng)用途可由具有
table 數(shù)據(jù)類型的變量替換。
Test 這是所有類型的測(cè)試類都必須實(shí)現(xiàn)的接口.在目前的框架中只有兩個(gè)這樣的類:TestCase和TestSuite. TestCase
這個(gè)類是大家在編寫自己的測(cè)試時(shí)要擴(kuò)展(extend)的主要的類.它是最簡(jiǎn)單的Test類型.TestCase的具體類(也就是擴(kuò)展TestCase的類)包含實(shí)現(xiàn)各種測(cè)試的方法以及可選的setUp和tearDown方法. TestSuite
這是Test的另一個(gè)子類.其目的就是把各種Test(測(cè)試)集中在一起,這包括TestCase,其他的TestSuite以及這二者的任意組合. Assert
這是TestCase的超類,它提供在編寫測(cè)試時(shí)要用到的所有assert方法. TestFailure
這個(gè)類簡(jiǎn)單封裝了測(cè)試運(yùn)行過(guò)程中產(chǎn)生的錯(cuò)誤(error)或失敗(failure).它記錄了失敗的Test(測(cè)試)以及引發(fā)錯(cuò)誤或失敗的例外(exception)(對(duì)于失敗的情況,就是AssertionFailedError). TestResult
這個(gè)類收集測(cè)試運(yùn)行的結(jié)果.除了報(bào)告失敗和錯(cuò)誤以外,它還負(fù)責(zé)感興趣的各方通告測(cè)試的開始和結(jié)束.
斷言 當(dāng)你在編寫測(cè)試方法的時(shí)候,將會(huì)大量使用從Assert繼承下來(lái)(通過(guò)TestCase)的各種功能. fail fail是最簡(jiǎn)單的方法. void
fail() void fail(String message) 調(diào)用fail()會(huì)導(dǎo)致測(cè)試立刻失敗.
1.調(diào)用構(gòu)造函數(shù)的例子 /** * Invoke a constructor on a class using
reflection. * * @param klass The class. * @param classes
The classes in the parameter list. * @param objects The objects to be
used as parameters. * @return The object constructed.
*/ public static Object invokeConstructor(final Class klass, final
Class[] classes, final Object[] objects) { try
{ Constructor constructor; try
{ constructor =
klass.getDeclaredConstructor(classes); } catch
(NoSuchMethodException e) { constructor =
klass.getConstructor(classes); } constructor.setAccessible(true); return
constructor.newInstance(objects); } catch
(NoSuchMethodException e) { throw new
RuntimeException(e.getMessage()); } catch
(InstantiationException e) { throw new
RuntimeException(e.getMessage()); } catch
(IllegalAccessException e) { throw new
RuntimeException(e.getMessage()); } catch
(InvocationTargetException e) { throw new
RuntimeException(e.getTargetException().getMessage()); } }
2.調(diào)用域的例子 /**
* Get the value of an instance field on an object using reflection.
* * @param instance The instance of the object. * @param
fieldName The name of the field. * @return The object returned by
getting the field. */ public static Object
invokeGetInstanceField(final Object instance, final String fieldName)
{ try { Field field; try
{ field =
instance.getClass().getField(fieldName); } catch
(NoSuchFieldException e) { field =
instance.getClass().getDeclaredField(fieldName); } field.setAccessible(true); return
field.get(instance); } catch (NoSuchFieldException e)
{ throw new
RuntimeException(e.getMessage()); } catch
(IllegalAccessException e) { throw new
RuntimeException(e.getMessage()); } }
3.調(diào)用類方法的例子 /**
* Invoke an instance method on an object using reflection. * *
@param instance The instance of the object. * @param methodName The name
of the method. * @param classes The classes in the parameter
list. * @param objects The objects to be used as parameters. *
@return The object returned by invoking the method. */ public
static Object invokeInstanceMethod( final Object instance, final
String methodName, final Class[] classes, final Object[] objects)
{
try { Method method; try
{ method = instance.getClass().getDeclaredMethod(methodName,
classes); } catch (NoSuchMethodException e)
{ method = instance.getClass().getMethod(methodName,
classes); } method.setAccessible(true); return
method.invoke(instance, objects); } catch
(NoSuchMethodException e) { throw new
RuntimeException(e.getMessage()); } catch
(IllegalAccessException e) { throw new
RuntimeException(e.getMessage()); } catch
(InvocationTargetException e) { throw new
RuntimeException(e.getTargetException().getMessage()); } }
4.調(diào)用靜態(tài)方法的例子 /**
* Invoke a static method on a class using reflection. * * @param
klass The class. * @param methodName The name of the method. *
@param classes The classes in the parameter list. * @param objects The
objects to be used as parameters. * @return The object returned by
invoking the method. */ public static Object
invokeStaticMethod( final Class klass, final String methodName,
final Class[] classes, final Object[] objects) {
try
{ Method method; try { method =
klass.getDeclaredMethod(methodName,
classes); } catch (NoSuchMethodException e)
{ method = klass.getMethod(methodName,
classes); } method.setAccessible(true); return
method.invoke(klass, objects); } catch
(NoSuchMethodException e) { throw new
RuntimeException(e.getMessage()); } catch
(IllegalAccessException e) { throw new
RuntimeException(e.getMessage()); } catch
(InvocationTargetException e) { throw new
RuntimeException(e.getTargetException().getMessage()); } }
constructor =
klass.getDeclaredConstructor(classes); 上面的函數(shù)形式如下: Constructor
getDeclaredConstructor(Class []
argumentTypes); 得到公共或非公共的指定構(gòu)造函數(shù),其實(shí)參與argumentTypes中所列類型匹配.
下面的也需要列出參數(shù),這里的objects就是參數(shù): return
constructor.newInstance(objects);
注意:其他也是如此.
對(duì)反射API的訪問(wèn)由安全管理器所控制.Field,Method和Constructor類都是由一個(gè)名為AccessibleObject的基類擴(kuò)展的.AccessibleObject類有一個(gè)主要的方法,名為setAccessible(),由此可以在訪問(wèn)特定的類成員時(shí)解除平常所設(shè)定的安全性.Javadoc說(shuō)明如下: setAccessible
public
void setAccessible(boolean flag) throws
SecurityException
Set the accessible flag for this object to the
indicated boolean value. A value of true indicates that the reflected object
should suppress Java language access checking when it is used. A value of false
indicates that the reflected object should enforce Java language access
checks.
First, if there is a security manager, its checkPermission
method is called with a ReflectPermission("suppressAccessChecks")
permission.
A SecurityException is raised if flag is true but
accessibility of this object may not be changed (for example, if this element
object is a Constructor object for the class Class).
A
SecurityException is raised if this object is a Constructor object for the class
java.lang.Class, and flag is true.
Parameters: flag - the
new value for the accessible flag Throws: SecurityException -
if the request is denied. See
Also: SecurityManager.checkPermission(java.security.Permission),
RuntimePermission
Class類提供了兩組方法來(lái)得到每一種特性.其中一組允許訪問(wèn)類的公共特性(其中包括由其超類所繼承得到的成員),而另一組則允許訪問(wèn)在類中直接聲明的任何公共或非公共成員(而不包括繼承得來(lái)的成員),這要取決于有何安全性考慮.以下是一些例子: .getFields()將返回一個(gè)Field對(duì)象數(shù)組,它表示一個(gè)類的所有公共變量,其中包括繼承得到的公共變量. .getDeclareFields()將返回一個(gè)數(shù)組,以表示類中聲明的所有變量,而不論其訪問(wèn)修飾符如何(不包括安全管理器不允許看到的變量),但是不包括繼承得到的變量. .對(duì)于構(gòu)造函數(shù),"所有構(gòu)造函數(shù)"和"所聲明構(gòu)造函數(shù)"之間無(wú)所謂差別(類不會(huì)繼承構(gòu)造函數(shù)),因此getConstructors()和getDeclaredConstructors()的唯一區(qū)別在于,前者返回的是公共構(gòu)造函數(shù),而后者則返回類的所有構(gòu)造函數(shù).
package net.sourceforge.jtds.jdbc;
import
java.text.MessageFormat; import java.util.Enumeration; import
java.util.Map; import java.util.ResourceBundle;
public final class
Messages { private static final String DEFAULT_RESOURCE =
"net.sourceforge.jtds.jdbc.Messages"; //默認(rèn)得資源 private static
ResourceBundle defaultResource; //和locale的綁定
private Messages()
{ }
public static String get(String key) { return
get(key, null); }
public static String get(String key, Object
param1) { Object args[] = {param1}; return get(key,
args); }
static String get(String key, Object param1, Object
param2) { Object args[] = {param1, param2}; return
get(key, args); }
private static String get(String key,
Object[] arguments) { try { ResourceBundle bundle =
loadResourceBundle(); String formatString =
bundle.getString(key); // No need for any formatting if no
parameters are specified if (arguments == null ||
arguments.length == 0) { return
formatString; } else { MessageFormat formatter
= new MessageFormat(formatString); return
formatter.format(arguments); } } catch
(java.util.MissingResourceException mre) { throw new
RuntimeException("No message resource found for message property " +
key); } }
private static ResourceBundle
loadResourceBundle() { if (defaultResource == null)
{ defaultResource =
ResourceBundle.getBundle(DEFAULT_RESOURCE); } return
defaultResource; }
static void loadDriverProperties(Map
propertyMap, Map descriptionMap) { final ResourceBundle bundle =
loadResourceBundle(); final Enumeration keys =
bundle.getKeys(); while (keys.hasMoreElements())
{ final String key = (String)
keys.nextElement(); final String descriptionPrefix =
"prop.desc."; final String propertyPrefix =
"prop."; if (key.startsWith(descriptionPrefix))
{ descriptionMap.put(key.substring(descriptionPrefix.length()),
bundle.getString(key)); } else if
(key.startsWith(propertyPrefix))
{ propertyMap.put(key.substring(propertyPrefix.length()),
bundle.getString(key)); } } } }
上面代碼中默認(rèn)得綁定名為:"net.sourceforge.jtds.jdbc.Messages".其實(shí)就是以工程為根目錄,尋找文件Messages.properties.這里查找的方式和類是一樣的.比如:"net.sourceforge.jtds.jdbc.Messages",就是工程根目錄下的net/sourceforge/jtds/jdbc/下的Messages.properties文件. 這個(gè)文件定義很多的屬性,要得到只要用get方法.
注意這里的defaultResource
=
ResourceBundle.getBundle(DEFAULT_RESOURCE);沒有設(shè)定Locale值,所以文件名為Messages.properties.如果設(shè)置了Locale值的話,例如:defaultResource
= ResourceBundle.getBundle(DEFAULT_RESOURCE,
Locale.ENGLISH);那么它就會(huì)去查找文件Messages_en.properties.其他類似加后綴(Locale.CHINA是Messages_zh.properties).
關(guān)于java.text.MessageFormat類,下面通過(guò)一個(gè)例子就可以說(shuō)明: MessageFormat
mf = new MessageFormat("You have {0} messages."); Object[] arguments =
{"no"}; System.out.println(mf.format(arguments)); //"You have no
messages."
關(guān)于String.startsWith(String prex)是測(cè)試字符串是否以prex開頭.
private static int nextToken(String url, int pos, StringBuffer token)
{ token.setLength(0);
while (pos < url.length())
{ char ch = url.charAt(pos++);
if (ch == ':'
|| ch == ';') { break; }
if
(ch == '/') { if (pos < url.length() &&
url.charAt(pos) == '/')
{ pos++; }
break; }
token.append(ch); }
return
pos; }
上面代碼中token.setLength(0);的作用是每次都把字符串緩沖區(qū)清空,也就是重置的作用. 上面代碼作用是每次得到指定的一段.例如"jdbc:jtds:sqlserver://hostname/dbname" token為jdbc,jtds,sqlserver,hostname,dbname
"a".equalsIgnoreCase(token.toString())
public boolean
equalsIgnoreCase(String anotherString) 函數(shù)是忽略大小寫的比較兩個(gè)字符串.
|