ivaneeo's blog

自由的力量,自由的生活。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

#

用语句设置sqlserver的信息的语言:
set language 'us_english'
上面是把语言设置成美国英语.
set language 'Simplified Chinese'
上面是把语言设置成简体中文.

安装了 SQL Server 提供的三十三种语言。下面是语言列表。


用英语表示的名称 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
posted @ 2005-08-04 14:54 ivaneeo 阅读(279) | 评论 (0)编辑 收藏

CREATE TABLE #test (f_int INT,f_varchar VARCHAR(255))
上面创建了一张临时表.

临时表
SQL Server 支持临时表。临时表就是那些名称以井号 (#) 开头的表。如果当用户断开连接时没有除去临时表,SQL Server 将自动除去临时表。临时表不存储在当前数据库内,而是存储在系统数据库 tempdb 内。

临时表有两种类型:

本地临时表
以一个井号 (#) 开头的那些表名。只有在创建本地临时表的连接上才能看到这些表。

全局临时表
以两个井号 (##) 开头的那些表名。在所有连接上都能看到全局临时表。如果在创建全局临时表的连接断开前没有显式地除去这些表,那么只要所有其它任务停止引用它们,这些表即被除去。当创建全局临时表的连接断开后,新的任务不能再引用它们。当前的语句一执行完,任务与表之间的关联即被除去;因此通常情况下,只要创建全局临时表的连接断开,全局临时表即被除去。

现在,临时表的许多传统用途可由具有 table 数据类型的变量替换。
posted @ 2005-08-04 14:52 ivaneeo 阅读(210) | 评论 (0)编辑 收藏

Test 这是所有类型的测试类都必须实现的接口.在目前的框架中只有两个这样的类:TestCase和TestSuite.
  TestCase 这个类是大家在编写自己的测试时要扩展(extend)的主要的类.它是最简单的Test类型.TestCase的具体类(也就是扩展TestCase的类)包含实现各种测试的方法以及可选的setUp和tearDown方法.
  TestSuite 这是Test的另一个子类.其目的就是把各种Test(测试)集中在一起,这包括TestCase,其他的TestSuite以及这二者的任意组合.
  Assert 这是TestCase的超类,它提供在编写测试时要用到的所有assert方法.
  TestFailure 这个类简单封装了测试运行过程中产生的错误(error)或失败(failure).它记录了失败的Test(测试)以及引发错误或失败的例外(exception)(对于失败的情况,就是AssertionFailedError).
  TestResult 这个类收集测试运行的结果.除了报告失败和错误以外,它还负责感兴趣的各方通告测试的开始和结束.

断言
  当你在编写测试方法的时候,将会大量使用从Assert继承下来(通过TestCase)的各种功能.
  fail
    fail是最简单的方法.
    void fail()
    void fail(String message)
    调用fail()会导致测试立刻失败.
posted @ 2005-08-04 14:51 ivaneeo 阅读(188) | 评论 (0)编辑 收藏

1.调用构造函数的例子
/**
     * 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.调用域的例子
/**
     * 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.调用类方法的例子
/**
     * 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.调用静态方法的例子
/**
     * 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());
        }
    }
posted @ 2005-08-04 14:47 ivaneeo 阅读(401) | 评论 (0)编辑 收藏

constructor = klass.getDeclaredConstructor(classes);
上面的函数形式如下:
Constructor getDeclaredConstructor(Class [] argumentTypes);
得到公共或非公共的指定构造函数,其实参与argumentTypes中所列类型匹配.

下面的也需要列出参数,这里的objects就是参数:
return constructor.newInstance(objects);

注意:其他也是如此.
posted @ 2005-08-04 14:46 ivaneeo 阅读(310) | 评论 (0)编辑 收藏

对反射API的访问由安全管理器所控制.Field,Method和Constructor类都是由一个名为AccessibleObject的基类扩展的.AccessibleObject类有一个主要的方法,名为setAccessible(),由此可以在访问特定的类成员时解除平常所设定的安全性.Javadoc说明如下:
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类提供了两组方法来得到每一种特性.其中一组允许访问类的公共特性(其中包括由其超类所继承得到的成员),而另一组则允许访问在类中直接声明的任何公共或非公共成员(而不包括继承得来的成员),这要取决于有何安全性考虑.以下是一些例子:
.getFields()将返回一个Field对象数组,它表示一个类的所有公共变量,其中包括继承得到的公共变量.
.getDeclareFields()将返回一个数组,以表示类中声明的所有变量,而不论其访问修饰符如何(不包括安全管理器不允许看到的变量),但是不包括继承得到的变量.
.对于构造函数,"所有构造函数"和"所声明构造函数"之间无所谓差别(类不会继承构造函数),因此getConstructors()和getDeclaredConstructors()的唯一区别在于,前者返回的是公共构造函数,而后者则返回类的所有构造函数.
posted @ 2005-08-04 14:45 ivaneeo 阅读(332) | 评论 (0)编辑 收藏

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";  //默认得资源
  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));
            }
        }
    }
}

上面代码中默认得绑定名为:"net.sourceforge.jtds.jdbc.Messages".其实就是以工程为根目录,寻找文件Messages.properties.这里查找的方式和类是一样的.比如:"net.sourceforge.jtds.jdbc.Messages",就是工程根目录下的net/sourceforge/jtds/jdbc/下的Messages.properties文件.
这个文件定义很多的属性,要得到只要用get方法.

  注意这里的defaultResource = ResourceBundle.getBundle(DEFAULT_RESOURCE);没有设定Locale值,所以文件名为Messages.properties.如果设置了Locale值的话,例如:defaultResource = ResourceBundle.getBundle(DEFAULT_RESOURCE, Locale.ENGLISH);那么它就会去查找文件Messages_en.properties.其他类似加后缀(Locale.CHINA是Messages_zh.properties).

  关于java.text.MessageFormat类,下面通过一个例子就可以说明:
    MessageFormat mf = new MessageFormat("You have {0} messages.");
    Object[] arguments = {"no"};
    System.out.println(mf.format(arguments));  //"You have no messages."

  关于String.startsWith(String prex)是测试字符串是否以prex开头.
posted @ 2005-08-04 14:43 ivaneeo 阅读(391) | 评论 (0)编辑 收藏

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);的作用是每次都把字符串缓冲区清空,也就是重置的作用.
上面代码作用是每次得到指定的一段.例如"jdbc:jtds:sqlserver://hostname/dbname"
token为jdbc,jtds,sqlserver,hostname,dbname
posted @ 2005-08-04 14:38 ivaneeo 阅读(457) | 评论 (0)编辑 收藏

"a".equalsIgnoreCase(token.toString())

public boolean equalsIgnoreCase(String anotherString)
函数是忽略大小写的比较两个字符串.
posted @ 2005-08-04 14:35 ivaneeo 阅读(221) | 评论 (0)编辑 收藏

仅列出标题
共67页: First 上一页 59 60 61 62 63 64 65 66 67