• Tomcat5.0.X配置数据库连接池,是分别配置Resource和ResourceParams,如
    代码:
            <Resource name="jdbc/ExampleDB" auth="Container" type="javax.sql.DataSource"/>
              <ResourceParams name="jdbc/ExampleDB">
                <parameter>
                  <name>factory</name>
                  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                </parameter>
                <!-- Maximum number of dB connections in pool. Make sure you
                 configure your mysqld max_connections large enough to handle
                   all of your db connections. Set to 0 for no limit.
                -->
                <parameter>
                  <name>maxActive</name>
                  <value>100</value>
                </parameter>
                <!-- Maximum number of idle dB connections to retain in pool.
                     Set to 0 for no limit.
                     -->
                <parameter>
                  <name>maxIdle</name>
                  <value>30</value>
                </parameter>
                <!-- Maximum time to wait for a dB connection to become available
                     in ms, in this example 10 seconds. An Exception is thrown if
                     this timeout is exceeded.  Set to -1 to wait indefinitely.
                     -->
                <parameter>
                  <name>maxWait</name>
                  <value>10000</value>
                </parameter>
                <!-- MySQL dB username and password for dB connections  -->
                <parameter>
                  <name>username</name>
                  <value>root</value>
                </parameter>
                <parameter>
                  <name>password</name>
                  <value></value>
                </parameter>
                <!-- Class name for mm.mysql JDBC driver -->
                <parameter>
                  <name>driverClassName</name>
                  <value>com.mysql.jdbc.Driver</value>
                </parameter>
                <!-- The JDBC connection url for connecting to your MySQL dB.
                     The autoReconnect=true argument to the url makes sure that the
                     mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
                     connection.  mysqld by default closes idle connections after 8 hours.
                     -->
                <parameter>
                  <name>url</name>
                  <value>jdbc:mysql://192.168.0.88:3306/quickoa</value>
                </parameter>
              </ResourceParams>

    而在Tomcat5.5.X中,这两者合二为一了,直接配置Resource就可以了,如
    代码:
    <Resource name="jdbc/ExampleDB" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost/quickoa" username="root"
          password="" maxActive="100" maxIdle="30" maxWait="10000" />

    又,值得注意的是在Tomcat5.5.X中,dbcp组件需要自己额外下载的,不像在Tomcat5.0.X中已经附带了。
  • 2005年01月28日

    Hibernate - XDoclet Tutorial

    Tag:Java

    http://www.downside.ch/hibernate/
    The tutorial covers the generation of Hibernate mapping files with XDoclet. If you are new to the Hibernate/XDoclet combo and want to have a glimpse into the world of ORM tools or you are just interested in some mapping examples then this is for you.

  • 2005年01月28日

    blogbus改版了

    Tag:Default
    太久没来了,都不知道已经改版了,好像变得更简洁实用了。不过还不够稳定,时不时的就上不了;而且清新模版的图片有错,http://www.blogbus.com/blogbus/blog/images/templates/cube.gif
    应该为http://www.blogbus.com/blogbus/blog/images/cube.gif
  • 2005年01月10日

    纠错

    Tag:Java

    看到一篇文章:[JAVA]初学者的经验---为什么变量无法使用

    昨天试了一天

    public class temp

    {

    public String s=“hello“;

    public static void main(String[] args)

         System.out.println(s);

    }

    为什么总是执行不了,查了大量的资料(....)发现原来JAVA在加载时,先加载static的内容之后再加载其它,所以在打印时变量仍未声明,因而会出错。

    呵呵,初学者会常犯的错误。

    其实这种说法完全是错的,原文那里发不了评论,在这里说明一下,免得误导初学者。

    不是这个原因,原因是s是实例变量,没有对象的话,是不能引用实例变量的。
    你在main里面这样就可以了:
    temp t = new temp();
    System.out.println(t.s);

  • CharRange
        You use the CharRange class to create and maintain a range of characters. The class provides functionality to determine if a character lies in a certain range as well as to determine if one character range lies within another character range.

    CharSet
    The CharSet class simplifies creating and using a set of characters. The CharSet can be created from the characters in a string and is especially useful when you want to check if a certain string holds only valid characters. You could create a CharSet and then check each character in the string against the character set.

    CharSetUtils
    CharSetUtils provides static methods to handle character-related functionality that is often required during development

    Note  For CharSet, case does matter. As a result, the character b and the character B are not the same.
            System.out.println("B,o,k,e and r count = " +
                CharSetUtils.count("BorisBecker", new String[] { "Bo", "ker" })); //8
            System.out.println("Delete B,o,k,e and r = " +
                CharSetUtils.delete("BorisBecker", new String[] { "Bo", "ker" })); //isc
            //Keeps only the characters specified
            System.out.println("Keep B and o = " +
                CharSetUtils.keep("BorisBecker", "Bo")); //BoB
            //Removes specified character repetitions
            System.out.println("Squeeze B and o = " +
                CharSetUtils.squeeze("BBoooorisbbbecker", "Bo")); //Borisbbbecker

    ObjectUtils
    The ObjectUtils class is a simple one that provides a couple of useful features. The toString method that has been introduced in Lang version 2 can be useful to avoid one of the most deadly problems facing Java developers, the NullPointerException. You can use the toString method to return an empty string or a specified string if the String instance provided is null. You could now replace all ternary operator usages in the form strInstance= (strInstance == null ? "": strInstance); with strInstance = ObjectUtils.toString(strInstance);.

    SerializationUtils
    Working with Java Input/Output (I/O) has never been my favorite. Remembering numerous classes, their hierarchies, and when to use what can be quite a pain. You can use the SerializationUtils class to take up the task of serializing and deserializing objects, so you do not have to worry about object input and output streams.

    The SerializationUtils class also provides methods that can use a byte array to serialize and deserialize. A clone method is also provided that serializes an object to a byte array and then deserializes it back to achieve cloning of the object.

    RandomStringUtils
    RandomStringUtils is one class that you can have a lot of fun using. The class generates random strings based on various parameters specified. One great option is that you can use it to hold a daily lottery at your desk. The point, of course, is that the source code can be rigged to make you win! A commonly required business application for the RandomStringUtils class is to generate passwords.

    RandomStringUtils是一个设计用来随机生成文本位的类,这在密码的生成上很常见。其全部范围是unicode,并且支持英文字母、Ascii码、AsciiNumeric和数字的特别重载。

    StringUtils
    StringUtils is the class in the Lang component that provides the most number of static methods to use. StringUtils has methods that can do almost everything you could want to do with a string. The class provides more than 100 methods; you will learn about some of the most useful ones.

    The StringUtils class even has some methods such as equals, trim, and substring that do what java.lang.String methods do. The StringUtils methods, however, provide built-in handling for null strings. A string being null is one of the most common causes of NullPointerException being thrown, so using the StringUtils methods is a better option in cases where you might get a null string. The Javadocs for the StringUtils class list all the methods that are null safe. Another useful addition to the Javadocs in Lang 2 is that now every method in StringUtils has some usage examples.

    NULL 这个空值常常会导致程序的 NullPointerException, 在撰写接收使用者 request 程序的时候会特別麻烦, 需要多输入 null 的检查, 不如使用 EMPTY 空字串来得方便, 所以我们可以将一些 StringUtils.defaultString(request.getParameter("xxx")) 来确保不是 NULL.

    capitalise(String):一个String大写化函数(这里保留了英式拼法),它不像大多数字符串库那样使用toUpperCase,而是恰当地使用了toTitleCase。

    join(Object[], String):它把对象数组里每个对象的toString合并成带有指定定界符的单个String。所以join( {"A","B",C"}, ";")的结果是"A;B;C"。Iterator也可以被连接。

    split(String, String):它能分割带有定界符的文本。其功能没有StringTokenizer(它不能一次处理多组定界符)强大,但是能够很快、很容易地应用于很多场合。它是上一个合并方法的反向操作:split("A;B;C",";") => {"A", "B", "C"}。这个分割方法现在已经可以在 JDK 1.4的java.lang.String里找到了。

    reverseDelimitedString(String, String):这是个很有趣的方法。它能以定界符为基础颠倒一段文本。所以:reverseDelimitedString("org.apache.commons")的结果就变成了"commons.apache.org."

    replace(String, String, String):这个String替换方法常常是很让人期待的。JDK1.4能够使用正规表达式解决这个问题,但是StringUtils类所提供的基于String更简单的版本更常用。


    SystemUtils
    增加了一些 java 系统上面的处理, 例如检查 java 的版本 isJavaVersionAtLeast , 执行的作业系统等等..
    SystemUtils is a handy little class that reads the system properties and returns appropriate messages based on the property values. You can use this class to find more information about the host machine and operating system. The most common usage, however, is to check the version of the JSDK being used. So, if you are using the logging introduced in JSDK 1.4, you could first check if the version being used is 1.4 or higher, and only if it is do you use the JSDK 1.4 features.

    The class provides only three public static methods, one of which is deprecated. Dozens of useful public static variables handle specific cases.

    ClassUtils
    The ClassUtils class is a new class introduced with version 2. This class provides static methods that can fetch you more information about a class or an object without having to directly use the Reflection Application Programming Interface (API).

    However, think twice before using some of the methods; if your design is proper, you ideally should not have to put such checks in your code.

    StringEscapeUtils
    Having to handle Hypertext Markup Language (HTML), JavaScript, Structured Query Language (SQL), and Java simultaneously is very much a part of a Java developer's life. However, generating output in a different format or handling input in a different format can be quite a task.

    For example, say you want to display <p>MyName<p> on a Web page. If you just send this as part of the HTML, what would appear on the screen is a new paragraph with the word MyName in it. The <p> tags used would not be displayed. What you need to send in the HTML would be this line of code:

    &lt;p&gt;MyName&lt;p&gt;

    This would then result in you getting the expected display <p>MyName<p>. TheStringEscapeUtils class makes implementing these cases quite simple because it provides ways of converting characters to achieve the expected output.