java问题

DWR配置问题 跟所用的dwr.jar包相关 根据包结构不同可能有

 <servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
uk.ltd.getahead.dwr.DWRServlet
</servlet-class>

使用hibernate遇到中文的乱码问题

Hibernate中配置Mysql数据库如下:

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
#hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/test
hibernate.connection.username root
hibernate.connection.password password

hibernate.commection.url的值后面加上字符串“?useUnicode=true&characterEncoding=GBK”就可以解决了。

即修改后的url为:

hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK

Hibernate还有一种配置文件是xml格式的,文件名为:hibernate.cfg.xml

在xml文件中配置MySql数据库的定义如下:

    <session-factory name="/jndi/ContactsSessionFactory">

<!-- properties -->
<property name="hibernate.connection.driver_class">
org.gjt.mm.mysql.Driver
</property>

<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=GBK
</property>

<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.pool_size">4</property>
<property name="hibernate.show_sql">true</property>
<!-- mapping files -->
<mapping resource="hello/Message.hbm.xml"/>

</session-factory>

注意由于在XML文件中&符号是转义符,因此需要对其进行转义。即使用&amp;来代替。



Eclipse+Tomcat配置J2EE项目

Undeployment Failure could not be redeployed because it could not be completely removed in the undeployment phase. the most common cuase of this problem is attempting to redeploy while the server is running,which has locked one or more files.

to correct the deployment you will need to stop the server and then redeploy the project before restarting the server.

1、停止运行Tomcat,右键点击项目名称
2、点击“Properties”,在弹出窗口选中“Java Build Path”,再点“Libraries”书签
3、把所有项目的jar都Remove掉,然后再把这个项目的jar都加进来
4、添加完后,再次Redeploy
5、看到Successfully deplayed,即配置成功了。

Value '0000-00-00' can not be represented as java.sql.Timestamp

数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00”
程序使用select 语句从中取数据时出现以下异常:
java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date

“0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的但 java.sql.Date 将其视为 不合法的值 格式不正确

解决办法:
给jdbc url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull
zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,
对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null

 

eclipse导入工程中文乱码问题

修改单个工程的编码方式:
右击工程,在弹出的菜单中选择最后一项“Properties”
在打开的新窗口左边的菜单树中选择 Info(即第一个),然后在右面找到 Text file encoding ,选择 “other”,在下拉框中选择需要的编码方式(如没有则直接输入)。

在MYSQL中插入当前时间,就象SQL SERVER的GETDATE()相同

update news set title='xinwen2'  ,dep='1' ,depname='bumen1' ,add_time=getdate() where id= '2'--FUNCTION gl.getdate does not exist

NOW()函数以`\\\'YYYY-MM-DD HH:MM:SS\\\'返回当前的日期时间,可以直接存到DATETIME字段中。
CURDATE()以’YYYY-MM-DD’的格式返回今天的日期,可以直接存到DATE字段中。
CURTIME()以’HH:MM:SS’的格式返回当前的时间,可以直接存到TIME字段中。
例:insert into tablename (fieldname) values (now())


update news set title='xinwen2'  ,dep='1' ,depname='bumen1' ,add_time=now() where id= '2'

posted on 2012-03-31 17:38  bigshuai  阅读(379)  评论(0编辑  收藏  举报