Hibernate在Spring配dataSource
S2SH整合 2008-09-12 15:25 阅读160 评论0
字号: 大大 中中 小小
<!-- mysql数据源的配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306:dbname?characterEncoding=gb2312"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!—Sql Serverl2005数据源的配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value=" com.microso ......
package cn.vicky.reg;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MyEclipseReg {
// ///////////////////////////////////////////////////////////
// 运行该文件 输入用户名 点击回车即可生成 MyEclipse 6.0 和 7.0 通用户注册码
// /////////////////////////////////////////////////////////
private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";
public String getSerial(String userId, String licenseNum) {
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(1, 3);
cal.add(6, -1);
java.text.NumberFormat nf = new java.text.DecimalF ......
1.最简单的图形,一个消息框
import javax.swing.JOptionPane;
//表明程序使用javax.swing包的JOptionPane类
public class Dialog1{
public static void main(String[] args) {
// TODO Auto-generated method stub
//下句表明程序使用JOptionPane类的showMessageDialog方法1`
JOptionPane.showMessageDialog(null,"welcome to java");
}
}
2.仍然是简单的消息框,输入名字后显示欢迎消息
import javax.swing.JOptionPane;
public class NameDialog{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String name=
JOptionPane.showInputDialog("what is your name? ");
String message=
String.format("welcome,%s,to java programming! ",name);
JOptionPane.showMessageDialog(null,me ......
文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进
来!
用法: SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
这一行最重要,它确立了转换的格式,yyyy是完整的公元年,MM是月份,dd是日期,至于HH:mm:ss
就不需要我再解释了吧!
PS:为什么有的格式大写,有的格式小写,那是怕避免混淆,例如MM是月份,mm是分;HH是24小
时制,而hh是12小时制。
1.字符串转日期
2008-07-10 19:20:00 要把它转成日期,可以用 Date date = sdf.parse( " 2008-07-10 19:20:00 " );
2.日期转字符串
假如把今天的日期转成字符串可用 String str = sdf.format(new Date());
这个字符串内容的格式类似2008-07-10 19:20:00。
透过这个API我们便可以随心所欲的将日期转成我们想要的字符串格式,例如希望将日期输出成2008
年7月10日,我们可以这么写:
......
Java2核心技术第七版中文版第二卷
第600页,警告处这样说:
如果将jar放入jre/lib/ext目录中,并且在它的类中有一个类需要调用系统类或者扩展类,那么就会遇到麻烦。扩展类加载器并不使用类路径。
刚读到这里十分不解,为什么用到系统类或扩展类会发生错误?并且一个类怎么可能不会用到系统类?于是,找到英文版原文如下:
You can run into grief if you drop a JAR file into the jre/lib/ext directory and one of its classes needs to load a class that is not a system or extension class. The extension class loader does not use the class path.
看到了吗? NOT
a system or extension class
我看这应该不是翻译者的笔误,至少没有认真翻译,或者根本不懂。 ......
今天碰到一个很有意思的问题,就是关于使用LinkedList作为HashMap或者Hashtable得key,但是最后发现数据并没有存进去。
首先说一下HashMap,Hashtable吧,它们都继承了Cloneable, Map, Serializable。它们两个基本上是一样的,“The HashMap
class is roughly equivalent to Hashtable
, except that it is
unsynchronized and permits nulls.”。区别就是HashMap允许“ null
values and the null
key”,同时 unsynchronized。它的性能取决于“ initial capacity
and load factor
”,具体参考官方文档。HashMap还有一个特性就是不能保证存入的元素的顺序,“HashMap does not guarantee that the order
will remain constant over time。” 对于存入到里面的key,要求“To successfully store and retrieve objects from a hashtable, the
objects used as keys must implement the hashCode
method and the equals
method. ”。更具我的测试,其实这个对于HashMap也是适用的。
这个就和我今天碰到的问题联系上了,LinkedList类里面的hashCode()函数来源于List.hashCode(),具体如下:
......