(2017年7月28日11:39:44)
什么是HashSet
HashSet实现了Set接口,它不允许集合中有重复的值,当我们提到HashSet时,第一件事情就是在将对象存储在HashSet之前,要先确保对象重写equals()和hashCode()方法,这样才能比较对象的值是否相等,以确保set中没有储存相等的对象。如果我们没有重写这两个方法,将会使用这个方法的默认实现。
什么是HashMap
HashMap实现了Map接口,Map接口对键值对进行映射。Map中不允许重复的键。Map接口有两个基本的实现,HashMap和TreeMap。TreeMap保存了对象的排列次序,而HashMap则不能。HashMap允许键和值为null。HashMap是非synchronized的,但collection框架提供方法能保证HashMapsynchronized,这样多个线程同时访问HashMap时,能保证只有一个线程更改Map。
(2017年11月9日11:20:13)
XML里两个属性介绍:
targetNamespace 相当于java语言里的package
xmlns 相当于java语言里的import
(2017年12月19日11:08:46)
oracle:
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:数据库名"
sqlserver数据库连接驱动的的写法:
连接sqlserver2000:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
URL ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tempdb";
连接sqlserver2005\2008:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
URL ="jdbc:sqlserver://localhost:1433;DatabaseName=tempdb";
mysql:
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/数据库名?[后接参数]"
db2:
driver="com.ibm.db2.jdbc.app.DB2Driver"
url="jdbc:db2://localhost:5000/数据库名"
sybase:
driver="com.sybase.jdbc.SybDriver"
url="jdbc:sybase:Tds:localhost:5007/数据库名"
(2017年12月19日15:46:28)
application.xml中:
<!-- 定义数据源 dataSource-->
<beanid="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close">
<propertyname="driverClass"value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<propertyname="jdbcUrl"value="jdbc:sqlserver://localhost:1433;DatabaseName=SCM_DEV"/>
<propertyname="user" value="sa"/>
<propertyname="password" value="sa"/>
</bean>
<!--定义一个hibernate 的 sessionFactory -->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="configLocations">
<value>classpath:config/hibernate.cfg.xml</value>
</property>
<propertyname="dataSource" ref="dataSource"/>
</bean>
hibernate.cfg.xml中:
<hibernate-configuration>
<!--表明以下的配置是针对session-factory配置的,SessionFactory是Hibernate中的一个类,这个类主要负责保存HIbernate的配置信息,以及对Session的操作-->
<session-factory>
<!-- 自定义ConnectionProvider的类名, 此类用来向Hibernate提供JDBC连接 ( 此处目的是:解决错误Cannotunwrap to requested type [javax.sql.DataSource] )-->
<!-- <propertyname="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
配置数据库的驱动程序,hibernate在连接数据库时所用到的数据库的驱动程序
<propertyname="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
配置数据库的连接URL,localhost是服务器名称,DEV_NEW是数据库名
<propertyname="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=SCM_DEV</property>
数据库登录名
<propertyname="hibernate.connection.username">sa</property>
数据库登录密码
<propertyname="hibernate.connection.password">sa</property> -->
..........................要么在hibernate.cfg.xml中加载数据库驱动和配置连接池,要么在application.xml中加载数据库驱动和连接池,并且配上dataSource, 两者的其他配置都可以在hibernate.cfg.xml里写,但是使用的是hibernate3,
(2018年2月28日15:38:48)
若单独使用hibernate和c3p0整合,则在hibernate.cfg.xml中写连接池、驱动等配置,
若hibernate、spring、c3p0想整合,则在application.xml中写dataSource等
hibernate获取session的两种方式:
// Session session =sessionFactory.openSession();
// Session session =sessionFactory.getCurrentSession();
(2018年3月9日16:07:55)
Hibernate3中:继承HibernateDaoSupport和不继承HibernateDaoSupport配置文件有区别:
继承HibernateDaoSupport的:如:
在spring配置文件中可以这么写:
若使用注释的话这么写:
不继承HibernateDaoSupport的则使用注入:
而spring配置文件:
注意:在上面图中<property name="sessionFactory"ref="sessionFactory"></property>没有这句话,程序启动报了Invocationof init method failed; nested exception is java.lang.IllegalArgumentException:'sessionFactory' or 'hibernateTemplate' is required错误,我估计是要直接向一般的DAOImpl中注入sessionFactory。
(2018年3月16日16:02:41)
(2018年4月13日16:28:04)
对于BufferedInputStream的理解:
BufferedInputStream自带8M缓冲区,我们自己又定义byte[]buf=newbyte[1024*1024];那bis.read(buf)就会去,8M缓冲区取数据,读到自己的1M缓冲区,直到碰到bos.write(buf,0,len) 把1M缓冲区的数据放到另外一个输出流的8M缓冲区里,输出流满8M就往外写东西,