MYSQL5

来源:互联网 发布:手机网络助手 编辑:程序博客网 时间:2024/05/23 01:58

MySQL5

mysql服务命令行:启动,查看数据库和表方法等  

net start mysql启动服务

net stop mysql停止服务

mysql  -u用户名 -p  (回车) 之后会提示你输入密码,你也可以直接把密码跟在p后面

Mysql -u root -p

exit quit 都能退出

create database databaseName 建立数据库

show databases查看创建的数据库有哪些

show tables查看数据库中的表有哪些,(之前别忘了use databasename,例如use  mysql

怎么启动mysql服务

方法一:net start mysql(或者是其他服务名)

方法二:XP下启动MySQL服务 

MySql安装目录:“d:\MySql\”

进入命令行输入窗口(Dos命令输入)

进入“d:\MySql\bin”目录下运行“mysqld -u root” 命令。写法:

d:\MySql\bin\mysqld -u root (Enter)

运行后在进程管理中有mysql的进程,运行成功(可能需要手动关闭命令窗口)

然后在“d:\MySql\bin\”目录下运行“mysql” 命令

写法:

d:\MySql\bin\(Enter)

屏幕出现:

mysql>

然后就可以输入数据库语句。

MYSQL创建数据库时候直接指定编码和排序规则 

mysql 创建 数据库时指定编码很重要,很多开发者都使用了默认编码,但是我使用的经验来看,制定数据库的编码可以很大程度上避免倒入导出带来的乱码问题。

我们遵循的标准是,数据库,表,字段和页面或文本的编码要统一起来

很多mysql数据库工具(除了phpmyadmin,我偶尔用,功能强速度慢)都不支持创建时指定数据库编码,当然可以改my.ini来解决这个问题,但是需要重新启动mysql,不过用下面的语句会更有效

GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

注意:如果不是通过my.ini配置文件设置的内容,只在当前状态下有效,当重启数据库服务后失效。所以如果想要不出现乱码只有修改my.ini文件,数据库编码可以在创建数据库时候指定UTF8,如下:

|character_set_client      | utf8                                  |

| character_set_connection | utf8                                  |

| character_set_database   | utf8                                  |

| character_set_filesystem | binary                                |

| character_set_results    | utf8                                  |

| character_set_server     | latin1                                |

| character_set_system     | utf8           

注意该配置| character_set_server     | latin1 无法设置成UTF8

交互时候仍然会出现乱码。

只有当修改my.ini中设置UTF8,才会全部修改成UTF8

-------------------------

mysql设置编码命令 

SET character_set_client = utf8; 

SET character_set_connection = utf8; 

SET character_set_database = utf8; 

SET character_set_results = utf8;/*这里要注意很有用*/ 

SET character_set_server = utf8; 

SET collation_connection = utf8_bin; 

SET collation_database = utf8_bin; 

SET collation_server = utf8_bin; 

my.ini中配置默认编码 

default-character-set=utf8 

连接数据库设置编码 

jdbc:mysql://192.168.0.5:3306/test?characterEncoding=utf8 

/*****************************************javamysq编码对应****************************************/ 

java中的常用编码UTF-8;GBK;GB2312;ISO-8859-1; 

对应mysql数据库中的编码utf8;gbk;gb2312;latin1

---------------------------

数据库连接串中指定字符集URL=jdbc:mysql://yourIP/college?user=root&password=yourPassword&useUnicode=true&characterEncoding=gbk 

1、将文本文件的内容导入到数据库中

Mysql>load data local infile 'D:\\data.txt' into table 表名 fields terminated by '\t';

load data local infile 'D:\\country.txt' into table country fields terminated by '\t';

load data local infile 'D:\\province.txt' into table province fields terminated by '\t';

load data local infile 'D:\\city.txt' into table city fields terminated by '\t';

load data local infile 'D:\\town.txt' into table town fields terminated by '\t';

load data local infile 'D:\\university.txt' into table university fields terminated by '\t';

load data local infile 'D:\\junior.txt' into table junior fields terminated by '\t';

load data local infile 'D:\\senior.txt' into table senior fields terminated by '\t';

load data local infile 'D:\\techschool.txt' into table techschool fields terminated by '\t';

load data local infile 'D:\\localProvince.txt' into table localProvince fields terminated by '\t';

load data local infile 'D:\\localCity.txt' into table localCity fields terminated by '\t';

load data local infile 'D:\\users.txt' into table users fields terminated by '\t';

Cmd>netstat -nao

---启动MySQL

MySQL>MySQL Server 5.1>Bin>

mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --console --skip-grant-tables

--error 1366

mysql#1366错误是在mysql5.0.2以上版本才出现的,不管是编码还是字段不符合规则,

就通不过mysql严格的数据检查,#1366错误就是这样出现的。当然如果你有修改my.ini的权限,

通常#1366是很好解决掉的。

只要把my.ini里的

Sql-mode=

"STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

这句话修改成sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"就可以了。

虚拟主机通常没有这种修改权限,如果是编码问题导致的#1366错误,那么请看我下面的介绍吧。或许对你有些帮助。

情况1:如果忘记了 MySQL 的 root 密码,可以用以下方法重新设置:

整理了以下四种在MySQL中修改root密码的方法,可能对大家有所帮助!

方法1: 用SET PASSWORD命令

  mysql -u root

  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

方法2:用mysqladmin

  mysqladmin -u root password "newpass"

  如果root已经设置过密码,采用如下方法

  mysqladmin -u root password oldpass "newpass"

方法3: 用UPDATE直接编辑user

  mysql -u root

  mysql> use mysql;

  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

  mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样

 1. KILL掉系统里的MySQL进程;

 2. 用以下命令启动MySQL,以不检查权限的方式启动;

  mysqld_safe --skip-grant-tables&

3. 然后用空密码方式使用root用户登录 MySQL

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

mysql> FLUSH PRIVILEGES;

Mysql>quit;

   

   

    

Mysql>create table emp( empno int,ename varchar(20),job varchar(20),hiredate timestamp default now(),sal int);

最近碰到一个MySQL5数据库的问题。就是一个标准的servlet/tomcat网络应用,后台使用MySQL数据库。问题是待机一晚上后,第二天早上第一次登录总是失败。察看日志发现如下错误:

“com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.”

经过一番调研,发现很多人都碰到过类似问题,但网上令人满意的回答并不多。MySQL网站上的提问也很多,但并没有正确答案;百度知道上倒是有一个近似正确的回答。现将本人的解决办法总结一下:

上述问题是由MySQL5数据库的配置引起的。mysql5将其连接的等待时间(wait_timeout)缺省为8小时。在其客户程序中可以这样来查看其值:

mysql>

mysql> show global variables like 'wait_timeout';

+---------------+---------+

| Variable_name | Value   |

+---------------+---------+

| wait_timeout  | 28800   |

+---------------+---------+

1 row in set (0.00 sec)

28800 seconds,也就是8小时。

如果在wait_timeout秒期间内,数据库连接(java.sql.Connection)一直处于等待状态,mysql5就将该连接关闭。这时,你的Java应用的连接池仍然合法地持有该连接的引用。当用该连接来进行数据库操作时,就碰到上述错误。这解释了为什么我的程序第二天不能登录的问题。

你可能会想到在tomcat的数据源配置中有没有办法解决?的确,在jdbc连接url的配置中,你可以附上“autoReconnect=true”,但这仅对mysql5以前的版本起作用。增加“validation query”似乎也无济于事。

本人觉得最简单的办法,就是对症下药:既然问题是由MySQL5的全局变量wait_timeout的缺省值太小引起的,我们将其改大就好了。

查看MySQL5的手册,发现对wait_timeout的最大值分别是24/365天(windows/Linux)。以windows为例,假设我们要将其设为21天,我们只要修改mysql5的配置文件“my.ini”mysql5 installation dir),增加一行:wait_timeout=1814400

需要重新启动MySQL5

Linux系统配置文件:/etc/my.cnf

测试显示问题解决了。

    mysql -u root

    4. 修改root用户的密码;

    mysql> update mysql.user set password=PASSWORD('新密码') where User='root';

    mysql> flush privileges

    mysql> quit

5. 重新启动MySQL,就可以使用新密码登录了

修改MySQL的端口号

装了MySql,装的时候一冲动把端口号改成8000了,结果连不上去了,怎么样可以把端口号改过来?

找到my.ini文件。

[mysqld] 下的

port=3306 改了

No rules found matching 'Server/Service/Engine/Host/Logger'.

对于tomcat5.0 配置数据源的时候要求在server.xml中进行修改加上例如:

   <DefaultContext reloadable="true" crossContext="true">

    <Resource name="jdbc/juddiDB" scope="Shareable" type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/juddiDB">

     <parameter>

      <name>url</name>

      <value>jdbc:mysql://localhost/juddi</value>

     </parameter>

     <parameter>

      <name>driverClassName</name>

      <value>org.gjt.mm.mysql.Driver</value>

     </parameter>

     <parameter>

      <name>username</name>

      <value>root</value>

     </parameter>

     <parameter>

     <!--帐号密码根据数据库安装配置修改-->

     <name>password</name>

      <value>******</value>

     </parameter>

    </ResourceParams>

   </DefaultContext>

这样的代码。

但是对于tomcat6.0.16的版本,配置数据源一般不修改server.xml,而是在context.xml中对数据源进行相应的配置,如:

<Resource name="jdbc/juddiDB" scope="Shareable" type="javax.sql.DataSource"

     maxActive="100" maxIdle="30" maxWait="10000"

     username="root" password="root" driverClassName="com.mysql.jdbc.Driver"

     url="jdbc:mysql://localhost:3306/juddi"/>

不然配置不对,可能会报tomcat版本错误,错误如下:

警告:   No rules found matching 'Server/Service/Engine/Host/Context/Logger'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/name'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/value'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/name'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/value'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/name'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/value'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/name'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter/value'.

2009-7-12 13:28:49 org.apache.tomcat.util.digester.Digester endElement

警告:   No rules found matching 'Server/Service/Engine/Host/Context/ResourcePara

ms/parameter'.

java jdbc java.lang.ClassNotFoundException: org.git.mm.mysql.Driver  

java.lang.ClassNotFoundException: org.git.mm.mysql.Driver 

解决办法

将 org.git.mm.mysql.Driver -com.mysql.jdbc.Driver

应该是mysql的驱动类加载错了,一般为com.mysql.jdbc.Driver,从没见过你的这种写法,我看你用的是5.1就更应该是这个了,再查查吧,

1、你的jar引错了

2、你的驱动类写错了。

试试看吧 

如何将一个.sql文件导入到mysql数据库中的一个数据库里

D:\> mysql -uroot -ppassword

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 18508

Server version: 5.1.22-rc Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use db

Database changed

mysql> source D:\\file.sql

Mysql>source D:\\whx\我的智囊团—数据库创建脚本.sql;

Source D:\\xiaonei.sql;

Mysql>source D:\\whx\123.sql;

Mldn智囊团表

/*==============================================================*/

/* DBMS name:      MySQL 4.0                                    */

/* Created on:     2007-6-28 15:25:46                           */

/*==============================================================*/

drop table if exists admin;

drop table if exists answer;

drop table if exists subitem;

drop table if exists item;

drop table if exists question;

drop table if exists user;

/*==============================================================*/

/* Table: admin                                                 */

/*==============================================================*/

create table admin

(

   id   INT AUTO_INCREMENT PRIMARY KEY ,

   adminid                        VARCHAR(50)  not null unique,

   adminpwd                       VARCHAR(50) not null

) ;

Insert into admin values(1,'admin','admin');

Insert into admin values(2,'administrator','admin');

Insert into admin values(3,'administor','admin');

Insert into admin values(4,'admintor','admin');

Insert into admin values(5,'admintor','admin');

/*==============================================================*/

/* Table: item                                                  */

/*==============================================================*/

create table item

(

   itemid         int auto_increment  not null,

   itemname       VARCHAR(50) not null unique,

   itemcode       int not null,

   primary key (itemid)

) ;

Insert into item(itemname,itemcode) values('.NET技术',1);

Insert into item(itemname,itemcode) values('Java技术',1);

Insert into item(itemname,itemcode) values('Web开发',1);

Insert into item(itemname,itemcode) values('PHP',1);

Insert into item(itemname,itemcode) values('MS-SQL server',1);

Insert into item(itemname,itemcode) values('数据库开发',1);

Insert into item(itemname,itemcode) values('硬件/嵌入开发',1);

Insert into item(itemname,itemcode) values('开发语言框架',1);

Insert into item(itemname,itemcode) values('云计算技术',1);

Insert into item(itemname,itemcode) values('IBM技术区',1);

 

/*==============================================================*/

/* Table: subitem                                               */

/*==============================================================*/

create table subitem

(

   subid      int  auto_increment    not null,

   subname    varchar(50) not null,

   itemid      int,

   subcode     int not null,

   primary key (subid) ,

   foreign key (itemid) references item(itemid) on delete cascade

) ;

Insert into subitem (subname,itemid,subcode) values('C#',1,1);

Insert into subitem (subname,itemid,subcode) values('C# Builder',1,1);

Insert into subitem (subname,itemid,subcode) values('F#J#',1,1);

Insert into subitem (subname,itemid,subcode) values('ASP.NET',1,1);

Insert into subitem (subname,itemid,subcode) values('NET Framework',1,1);

Insert into subitem (subname,itemid,subcode) values('Web services',1,1);

Insert into subitem (subname,itemid,subcode) values('VB.NET',1,1);

Insert into subitem (subname,itemid,subcode) values('VC',1,1);

Insert into subitem (subname,itemid,subcode) values('Delphi',1,1);

Insert into subitem (subname,itemid,subcode) values('LINQ',1,1);

Insert into subitem (subname,itemid,subcode) values('VSTS',1,1);

Insert into subitem (subname,itemid,subcode) values('Java SE',2,1);

Insert into subitem (subname,itemid,subcode) values('J2ME',2,1);

Insert into subitem (subname,itemid,subcode) values('Java Web开发',2,1);

Insert into subitem (subname,itemid,subcode) values('Java EE',2,1);

Insert into subitem (subname,itemid,subcode) values('Eclipse',2,1);

Insert into subitem (subname,itemid,subcode) values('JBoss',2,1);

Insert into subitem (subname,itemid,subcode) values('高性能web开发',2,1);

Insert into subitem (subname,itemid,subcode) values('ASP',3,1);

Insert into subitem (subname,itemid,subcode) values('ASP.NET',3,1);

Insert into subitem (subname,itemid,subcode) values('JSP',3,1);

Insert into subitem (subname,itemid,subcode) values('PHP',3,2);

Insert into subitem (subname,itemid,subcode) values('开源资源',4,1);

Insert into subitem (subname,itemid,subcode) values('基础编程',4,1);

Insert into subitem (subname,itemid,sucode) values('Freamwork',4,1);

Insert into subitem (subname,itemid,subcode) values('Java SE',4,1);

Insert into subitem (subname,itemid,subcode) values('Java EE',4,1);

Insert into subitem (subname,itemid,subcode) values('Java SE',5,1);

Insert into subitem (subname,itemid,subcode) values('Java EE',5,1);

Insert into subitem (subname,itemid,subcode) values('Java2EE',5,1);

/*==============================================================*/

/* Table: user                                                  */

/*==============================================================*/

create table user

(

   id   INT AUTO_INCREMENT PRIMARY KEY ,

   userid         VARCHAR(50)  not null,

   userpwd                        VARCHAR(50),

   userques                       VARCHAR(50),

   userans                        VARCHAR(50),

   usermail       VARCHAR(50) not null,

   integral int default 0 check(integral>=0),

   grade  int default 1 check (grade>=1),

   sex                            VARCHAR(2) default '',

   realname                       VARCHAR(50)

) ;

Insert into user(userid,userpwd,userques,userans,usermail,integral,grade,sex,realname) values('whx','whx','C++','C++','wang010366@vip.qq.com',10000,7,'','王红祥');

Insert into user(userid,userpwd,userques,userans,usermail,integral,grade,sex,realname) values('tj','tj','医学','医学','tj010366@qq.com',5,5,'','唐娇');

/*==============================================================*/

/* Table: question                                              */

/*==============================================================*/

create table question

(

   qid             int             auto_increment               not null,

   title                          VARCHAR(50) not null,

   content                        text,

   itemid                         int not null,

   subid                          int not null,

   userid                         VARCHAR(50),

   grade                          int,

   offerscore                     int not null,

   status int default 1 check status in (1,2,3),

   questiontime                   timestamp default now(),

   clickcount  int default 0 check(clickcount>=0),

   acceptflag  int default 2 check acceptflag in(1,2),

   commenflag  int default 1 check commenflag in(1,0),

   primary key (qid)

) ;

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',1,1,'whx',7,10,1,0,2,1);

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',2,1,'whx',7,100,1,0,2,1);

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',3,1,'whx',7,10,1,0,2,1);

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',4,1,'whx',7,10,1,0,2,1);

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',5,1,'whx',7,10,1,0,2,1);

Insert into question(title,content,itemid,subid,userid,grade,offerscore,status,clickcount,acceptflag,commenflag) values('C++','wanghongxiang',6,1,'whx',7,10,1,0,2,1);

/*==============================================================*/

/* Table: answer                                                */

/*==============================================================*/

create table answer

(

   aid               int            auto_increment         not null,

   quesans                        VARCHAR(50),

   userid                         VARCHAR(50) not null,

   grade                          int ,

   anstime                        timestamp default now(),

   status   int  default 2 check status in(1,2),

   qid                            int,

   primary key (aid) ,

   foreign key (qid) references question(qid) on delete cascade 

) ;

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,1);

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,2);

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,3);

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,4);

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,5);

Insert into answer(quesans,userid,grade,status,qid) values('C++','tj',5,2,6);

Insert into answer(quesans,userid,grade,status,qid) values('C++','whx',7,2,1);

/*java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

 * 原因:

Hibernate 3.0.x/3.1.x升级到最新的3.2版之后,3.2版的很多sql函数如count(),

 sum()的唯一返回值已经从Integer变为Long,如果不升级代码,会得到一个ClassCastException。 

这个变化主要是为了兼容JPA,可以在hibernate.org的最新文档中找到说明。 

解决方案:

1.hibernate尤其解决方案。当使用hibernate的查询函数count(),sum()等的值时(注意:一定是只返回唯一值的并且为数字格式是才可以)

可已调用query的uniqueResult();方法  此方法返回Object对象,只需要把它转为Number类型,然后调用.intValue()即可。

例如:Integer count=((Number)(session.createQuery(hql)).uniqueResult()).intValue(); 

2.可以将long转为字符串,然后将字符串再转为integer;

Long i = (Long) session.createQuery(hql).uniqueResult();

Integer ii= new Integer(String.valueOf(i)); 

OK,这两种方案即可解决此类问题~

 */

public int getByUseridCount(String userid) throws Exception {

int count = 0;

String hql = "SELECT COUNT(q.qid) FROM Question AS q WHERE q.userid=?";

/*Query q = super.getSession().createQuery(hql);

q.setString(0, userid);

List all = q.list();

count = (Integer) all.get(0);*/

Query q = super.getSession().createQuery(hql);

q.setString(0, userid);

List all = q.list();

//解决java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

Long i = (Long) all.get(0);

count=new Integer(String.valueOf(i));

return count;

}

org.apache.jasper.JasperException

/jsp/user/list_myquestion.jsp(25,38) Attribute value 

request.getAttribute("keyWord") is quoted with " which must 

be escaped when used within the value

错误行的代码:

<jsp:param        name="keyWord" value=

"<%=request.getAttribute("keyWord")%>" />

错误信息:

Attribute value request.getAttribute(\"keyWord") is quoted with "

 which must be escaped when used within the value

解决方案:①有可能是TOMCAT的版本问题。

         ②按照错误的提示,进行了字符转义将其改成(\"keyWord\")"就行了。

java.lang.NullPointerException

一般报java.lang.NullPointerException的原因有以下几种: 

·字符串变量未初始化; 

·接口类型的对象没有用具体的类初始化,比如: 

List lt; 会报错 

List lt = new ArrayList(); 则不会报错了 

·当一个对象的值为空时,你没有判断为空的情况。 

 你可以试着把下面的代码前加一行代码: 

if(rb!=null); 

  ...................

String类型的对象可以做如下判断

if(rb!==null&&!"".equals(rb)) 

…… 

当然还可以多做一个判断,是否不为空字符串

if(rb!==null&&!"".equals(rb.trim())) 

public User queryByUserid(String userid) throws Exception {

User user = null;

String hql = "FROM User AS u WHERE u.userid=?";

Query q = super.getSession().createQuery(hql);

q.setString(0, userid);

/*List all = q.list();*/

List all=new ArrayList();

all=q.list();

if (all.size() > 0) {

user = (User) all.get(0);

}

return user;

}

public ActionForward login(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

UserForm userForm = (UserForm) form;

String ccode = (String)

 request.getSession().getAttribute("ccode");

String checkcode = userForm.getCheckcode();

if (!(checkcode.equals(ccode))) {

ActionMessages errors = new ActionMessages();

errors.add("checkcode"new ActionMessage("checkcode.error"));

super.saveErrors(request, errors);

return mapping.getInputForward();

}

User user = new User();

MD5Code md5 = new MD5Code();

user.setUserid(userForm.getUserid());

user.setUserpwd(md5.getMD5ofStr(userForm.getUserpwd()));

//输出登录的用户名

System.out.println(""+userForm.getUserid());

boolean flag = false;

try {

//传过来的用户名有空能是空的

if(user!=null)

{

           //要报错

flag = this.iuserdao.login(user);

}

catch (Exception e) {

e.printStackTrace();

}

//特别注意一下

if (!flag) {

// 登陆成功

// 向session之中设置内容

request.getSession().setAttribute("userid", user.getUserid());

request.getSession().setAttribute("grade", user.getGrade());

return mapping.findForward("loginsuccess");

else {

request.setAttribute("flag""error");

return mapping.findForward("loginfailure");

}

}

public void doFilter(ServletRequest req, ServletResponse resp,

FilterChain chain) throws IOException, ServletException {

req.setCharacterEncoding(this.charset);

//报错

chain.doFilter(req, resp);

}

org.hibernate.exception.SQLGrammarException

could not execute query

sql语法错误,检查你的hibernate配置和你的数据表结构是否正确。

 应该是你的配置和你数据表结构不一样,好好检查拼写 

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:

 Every derived table must have its own alias

在sessionFactory中配置的数据库方言引起的错误

//oracle

hibernate.dialect=org.hibernate.dialect.Oracle9iDialect

//SQLServer

hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect

// MySql

hibernate.dialect=org.hibernate.dialect.MySQLDialect

2013-04-29 16:12:06,062 INFO [org.hibernate.impl.SessionFactoryImpl] - closing

2013-4-29 16:12:06 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [/MyZhiNangTuan] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

2013-4-29 16:12:06 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

严重: The web application [/MyZhiNangTuan] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.

2013-4-29 16:12:06 org.apache.coyote.http11.Http11AprProtocol destroy

信息: Stopping Coyote HTTP/1.1 on http-8080

2013-4-29 16:12:06 org.apache.coyote.ajp.AjpAprProtocol destroy

信息: Stopping Coyote AJP/1.3 on ajp-8009

看报的异常信息是应用程序注册了JDBC驱动,但当程序停止时无法注销这个驱动,tomcat为了防止内存溢出,就给强制注销了。

 上网搜,发现网上有不少关于这个问题的讨论,说是DBCP的bug。

 详细如下:

https://issues.apache.org/jira/browse/DBCP-332 

 Description

 BasicDataSource's method close() doesn't deregister JDBC driver. This causes permgen memory leaks in web server environments, during context reloads. For example, using Tomcat 6.0.26 with Spring, and BasicDataSource declared in Spring context, there is a message printed at web application reload:

 SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

 I was able to fix it by overriding close method this way:

[java] view plaincopy

01.public class XBasicDataSource extends BasicDataSource {  

02.    @Override  

03.    public synchronized void close() throws SQLException {  

04.        DriverManager.deregisterDriver(DriverManager.getDriver(url));  

05.        super.close();  

06.    }  

07.}  

 but I think it should be probably the default behavior of BasicDataSource. Or perhaps there should be some flag/setting on BasicDataSource, named "deregisterDriverAtClose" or so.

我的系统没有用spring配置数据源。

tomcat从6.0.24版本之后引入了内存泄漏侦测的功能,当发现系统有垃圾无法回收时,就会输出日志信息。

 看了很多关于这个问题的讨论,好像也没发现什么好的解决方法。有的说把tomcat的内存监听器关了就不会报这个异常,可是不报不等于没问题,依然无法解决啊。感觉应该是Hibernate的默认连接池对数据库连接的管理存在bug,其不会对连接是否有效进行检查,所以会出现异常。

 在网上搜了关于Hibernate配置MySQL的资料,发现Mysql有个8小时问题,即系统如果超过8个小时没有被访问,mysql就会关闭空闲的Connection连接,而hibernate不会对连接是否有效进行检查,导致系统无法连接数据库。

 在看了很多资料后,基本上可以确定是数据库连接的管理出了问题,用的是Hibernate3,配置数据库的时候用的是Hibernate默认的连接池,尝试更换成了Proxool连接池。

 参考如下:

http://www.360doc.com/content/08/0101/10/53523_938529.shtml

 3. proxool连接池

       proxool跟c3p0以及dbcp不一样,它是自己生成连接的,因此连接信息放在proxool配置文件中。使用它时,需要将proxool-0.8.3.jar加入到classespath中。配置举例如下:

hibernate.cfg.xml

[html] view plaincopy

01.<?xml version="1.0" encoding="UTF-8"?>  

02.  

03.<!DOCTYPE hibernate-configuration PUBLIC  

04.  

05."-//Hibernate/Hibernate Configuration DTD 3.0//EN"  

06.  

07."http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  

08.  

09.<hibernate-configuration>  

10.  

11.<session-factory>  

12.  

13.        <!-- 显示实际操作数据库时的SQL -->  

14.  

15.        <property name="show_sql">true</property>  

16.  

17.        <!-- SQL方言,这边设定的是MySQL -->  

18.  

19.        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>  

20.  

21.<!—proxool的配置 -->  

22.  

23.       <property name="proxool.pool_alias">pool1</property>  

24.  

25.<property name="proxool.xml">ProxoolConf.xml</property>  

26.  

27.<property name="connection.provider_class">net.sf.hibernate.connection.ProxoolConnectionProvider</property>  

28.  

29.       <!-- 对象与数据库表格映像文件 -->  

30.  

31.       <mapping resource="com/amigo/pojo/User.hbm.xml"/>  

32.  

33.<mapping resource="com/amigo/pojo/Org.hbm.xml"/>  

34.  

35.  </session-factory>  

36.  

37.</hibernate-configuration>  

在hibernate.cfg.xml的同目录下编写proxool的配置文件:ProxoolConf.xml,该文件的配置实例如下:

ProxoolConf.xml

[html] view plaincopy

01.<?xml version="1.0" encoding="utf-8"?>  

02.<!-- the proxool configuration can be embedded within your own application's.  

03.Anything outside the "proxool" tag is ignored. -->  

04.<something-else-entirely>  

05.<proxool>  

06.<alias>pool1</alias>  

07.<!--proxool只能管理由自己产生的连接-->  

08.  

09.<!-- 驱动的url-->  

10.  

11.<!-- jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GBK-->  

12.  

13.<driver-url>… </driver-url>  

14.  

15.<!-- 驱动类,eg. com.mysql.jdbc.Driver-->  

16.  

17.<driver-class>… </driver-class>  

18.<driver-properties>  

19.  

20.<!-- 数据库用户名,eg. value为root-->  

21.  

22.<property name="user" value="…"/>  

23.  

24.<!-- 数据库密码,eg. value为root-->  

25.  

26.<property name="password" value="…."/>  

27.</driver-properties>  

28.<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->  

29.<house-keeping-sleep-time>90000</house-keeping-sleep-time>  

30.<!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受-->  

31.<maximum-new-connections>20</maximum-new-connections>  

32.<!-- 最少保持的空闲连接数-->  

33.<prototype-count>5</prototype-count>  

34.<!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->  

35.<maximum-connection-count>100</maximum-connection-count>  

36.<!-- 最小连接数-->  

37.<minimum-connection-count>10</minimum-connection-count>  

38.</proxool>  

39.</something-else-entirely>  

按照上面讲的加入了Proxool0.9.1的jar包并配置好了,测试时却不通过,报没有jdbc connection的异常,奇怪。一个哥们和我一起按照上面的配置,他的却通过了,看了他的配置文件发现他的hibernate.cfg.xml里依然配置有数据库的连接信息,这个应该不需要了,因为在Proxool.xml里配置了啊。难道是因为这个,我也加上连接信息进行测试,结果正常登录,把系统日期往后调了几天再进行登录测试,又报了一开始的那个异常。很明显我配的这个连接池没有起作用,很奇怪。我哥们把他的Hibernate.cfg.xml里的数据库连接配置去掉后,他的依然可以运行通过,而且系统调时间后也可以运行,说明这个连接池起作用了,问题终于算是解决了,很高兴。可是我们的代码是一样的,对比了各自的配置文件也都是一样的啊,为什么在我这不起作用呢?很是郁闷,难道是人品的问题?!不会的,我人品应该还可以啊,可是残酷的现实就摆在眼前。。。。。。不管了,都中午一点多了,午饭还没吃呢,去吃饭。

 在学校外面的兰州拉面馆吃了碗牛肉刀削面,回来后还是想着这个问题,搁心里憋的慌。想了一会,觉得应该还是Hibernate.cfg.xml和proxool.xml配置文件的问题,于是我把哥们的这两个配置文件拷贝到我的系统里,把我的替换掉。运行通过。。。。。。晕死,配置文件的内容是我直接拷贝网页上的,可能存在一些字符问题。这样测试还是不放心,又把系统放到了一个小服务器上跑段时间看还会不会出现问题。

 结果跑了几天后,依然正常。

org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [/rdms] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

后来在网上搜了搜,还是有不少人说这个问题吧,感觉出这个问题的原因可能是多种多样,并不是某个固定原因吧。我就简单说说我搜到一个的情况,和我自己的这个问题的解决。

 有篇老外的文章

http://confluence.atlassian.com/pages/viewpage.action?pageId=218275753

它里有提到个原因:

Causes

There is a ?memory leak detection feature introduced in Tomcat 6.0.25 that attempts to log objects that have failed to be Garbage Collected even though they been marked for removal. As the Tomcat and JVM is being shutdown, these messages are not applicable in this situation.

大概就是说tomcat 6.025以后引入了内存泄露侦测,对于垃圾回收不能处理的对像,它就会做日志。

老外提出的办法是要么用旧版本的tomcat,要么就在tomcat的server.xml文件中,把

<!-- Prevent memory leaks due to use of particular java/javax APIs-->

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>;

这个监听给关了。我试了把这个监听关了,就不会再报上面那个信息,但是这样子运行tomcat会不会有其他的问题,我就不得而知了。

一般tomcat-6.0以上会有问题

javax.servlet.jsp.JspException: Cannot retrieve mapping for action /jsp/user

在struts里面如果出现了这样的错误,其实很简单,也不用急。

其原因就是出现了一个action没有应对一个mapping。

解决的办法就是,查找你的JSP页面里面哪个没有对上你的action就成了。 

如何复制cmd中的内容

如何复制cmd中的内容今日,有朋友让帮忙在cmd中ping一下某ip地址,看看是否能够ping通。而且让我把ping的数据结果给他。

ping倒是没啥问题,但是如何将在cmd(老式的dos)界面中的字符copy给他成了一个问题。

参照平常在windows里面的方法就是左键选中起始位置,然后拖动鼠标到达终止位置,再ctrl+c,或者右键选择复制即可。但是在cmd的环境下,就没有这么简单了。通过短暂的“摸索”(小沉同志莫笑,偶们很菜地!)发现了在cmd环境下复制字符的方法,写出来给有用的着的人看看吧!

1、在需要复制的内容的起始部分,单击鼠标右键,选择“标记”;

2、此刻直接左键拖动鼠标即可实现内容的选定了;

3、选择完毕,直接按键盘的回车键,即可完成复制操作了!

 在spring2.0中,bean没有“singleton”这个属性,而是在“scope”中对它进行设定。“scope”可以设定为“singleton”和“prototype”默认情况下是“singleton”即和原先的“singleton=true”性质一样,如果要实现单例模式则将“scope”设定为“prototype”,即和原先版本的“singleton=false”一样。参考文档链接地址:http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

 cvc-complex-type.3.2.2: 

Attribute 'singleton' is not allowed to appear in element 'bean 

<bean name="/jsp/ques/item"

class="org.whx.znt.struts.action.ItemAction" scope="singleton">

<property name="iitemdao">

<ref bean="iitemdaoimpl" />

</property>

</bean>

具体配置方法:

Spring 1.*

<bean id="hibernateSessionFactory" 

class="org.hibernate.admin.component.HibernateSessionFactory" init-method="init" destroy-method="dispose" singleton="true">

-----------------------------------------------------------------

<bean name="/jsp/ques/item"

class="org.whx.znt.struts.action.ItemAction" singleton="true">

<property name="iitemdao">

<ref bean="iitemdaoimpl" />

</property>

</bean>

-----------------------------------------------------------------

Spring 2.0

spring-beans-2.0.dtd/xsd does not support 

singleton="true"/"false" anymore. Use 

scope="singleton/"prototype" instead!

<bean 

id="hibernateSessionFactory" class="org.hibernate.admin.component.HibernateSessionFactory" init-method="init" destroy-method="dispose" scope="singleton">

-----------------------------------------------------------------

<bean name="/jsp/ques/item"

class="org.whx.znt.struts.action.ItemAction" scope="singleton">

<property name="iitemdao">

<ref bean="iitemdaoimpl" />

</property>

</bean>

-----------------------------------------------------------------

java.lang.IllegalStateException异常解决办法 

最近在使用response.sendRedirect()时出现如下错误:

   java.lang.IllegalStateException

   org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)

经过分析、查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:

  response.sendRedirect("login.jsp");

   return;

原因是:在程序中两次调用了response.sendRedirect()方法。

 

 

jdk5.0文档中很清楚地介绍了出现IllegalStateException异常的可能情况:

1)同一个页面中再次调用response.sendRedirect()方法。

2)提交的URL错误,即不是个有效的URL。 

sendRedirect

 void sendRedirect(java.lang.String location)

 throws java.io.IOException

 Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading &apos;/&apos; the container interdivts it as relative to the current request URI. If the location is relative with a leading &apos;/&apos; the container interdivts it as relative to the servlet container root. 

 If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to. 

 Parameters: 

 location - the redirect location URL 

 Throws: 

 java.io.IOException - If an input or output exception occurs 

 java.lang.IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL

mysql获取当前时间

now()函数,你可以用select now();看下。

java.lang.IllegalArgumentException

public class IllegalArgumentExceptionextends RuntimeException抛出的异 常表明向方法传递了一个不合法或不正确的参数。 

Mysql>show tables;/显示数据库中有多少张表

Mysql>show databases;//娴熟数据库系统有多少个数据库

Exception in thread "main" java.lang.NoClassDefFoundError:

 com/sun/mail/util/LineInputStream 

如果你用myEclipse进行开发的话,运行时可能会出现以下的错误:

Exception in thread "main" java.lang.NoClassDefFoundError:

 com/sun/mail/util/LineInputStream

原因是jar包版本不统一,解决方法如下:

删除Java EE 5 Libraries/javaee.jar/mail里的包有东西.

具体方法如下:

用rar打开X:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins

/com.genuitec.eclipse.j2eedt.core_6.0.1.zmyeclipse601200710/data/

libraryset/EE_5/javaee.jar,然后删除mail,一切就ok了.

信息: ExtensionValidator[/MyZhiNangTuanDemo][commons-attributes-compiler.jar]: Required extension "ant" not found.

2013-5-6 16:30:08 org.apache.catalina.util.ExtensionValidator validateManifestResources

信息: ExtensionValidator[/MyZhiNangTuanDemo][commons-attributes-compiler.jar]: Required extension "qdox" not found.

2013-5-6 16:30:08 org.apache.catalina.util.ExtensionValidator validateManifestResources

信息: ExtensionValidator[/MyZhiNangTuanDemo][commons-attributes-compiler.jar]: Required extension "commons-attributes-api" not found.

2013-5-6 16:30:08 org.apache.catalina.util.ExtensionValidator validateManifestResources

信息: ExtensionValidator[/MyZhiNangTuanDemo][commons-attributes-compiler.jar]: Required extension "javadoc" not found.

2013-5-6 16:30:08 org.apache.catalina.util.ExtensionValidator validateManifestResources

信息: ExtensionValidator[/MyZhiNangTuanDemo]: Failure to find 4 required extension(s).

昨天用spring做了个定时器,用于定时扫描某通讯公司外网ftp服务器的约定路径下是否有我需要的文件并下载到本公司服务器上。记得以前做过类似的一个定时器,觉得手到擒来的事情,没想到又折腾了大半天,就是因为spring中commons-attributes-compiler.jar的使用问题。

   问题是这样的:扫面和下载程序,触发类和函数,web.xml和spring配置文件,这些准备工作都已经完成,就是在服务器启动的时候报错:

INFO: Deploying web application archive GRCC.war 

Sep 14, 2007 13:22:18 AM 

org.apache.catalina.util.ExtensionValidator validateManifestResources 

INFO: ExtensionValidator[/GRCC][commons-attributes-api.jar]: Required extension "ant" not found. 

Sep 14, 2007 13:22:18 AM 

org.apache.catalina.util.ExtensionValidator validateManifestResources 

INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension "ant" not found. 

Sep 14, 2007 13:22:18 AM 

org.apache.catalina.util.ExtensionValidator validateManifestResources 

INFO: ExtensionValidator[/GRCC][commons-attributes-compiler.jar]: Required extension "javadoc" not found. 

Sep 14, 2007 13:22:18 AM 

org.apache.catalina.util.ExtensionValidator validateManifestResources 

INFO: ExtensionValidator[/GRCC]: Failure to find 3 required extension(s). 

   Sep 14, 2007 13:22:18 AM 

org.apache.catalina.core.StandardContext start 

SEVERE: Error getConfigured 

Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext start 

SEVERE: Context [/GRCC startup failed due to previous errors 

Sep 14, 2007 13:22:18 AM org.apache.catalina.core.StandardContext stop 

INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/GRCC] has not been started

并导致本项目无法启动!

    从错误可以看出,commons-attributes-compiler.jar需要的"ant","javadoc","qdox"无法找到,我又检查了数遍,ant和qdox这些jar包我都已经加lib里了,可spring就是视而不见!我郁闷了好久,最后实在不行了,我决定解压commons-attributes-compiler.jar,看看它的庐山真面目,里面还真不复杂:META-INF\MANIFEST.MF,compile\org\apache\commons\attributes\anttasks.properties,LICENSE.txt,,

NOTICE.txt,后两个肯定是说明性的文件,我没有理会;第二个是属性文件,我看格式和注释都没有什么不妥;就MANIFEST.MF里面内容较多,并且有异常之处(我标出了):

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.5.3 

Created-By: Apache Maven

Built-By: hen

Package: org.apache.commons.attributes.compiler

Build-Jdk: 1.4.2_05

Extension-Name: commons-attributes-compiler

Specification-Title: Attribute Compiler

Specification-Vendor: The Apache Software Foundation

Implementation-Title: org.apache.commons.attributes.compiler

Implementation-Vendor: The Apache Software Foundation

Implementation-Version: 2.2

Extension-List: ant qdox commons-attributes-api javadoc

ant-Extension-Name: ant

ant-Implementation-Version: 1.5

ant-Implementation-URL: http://www.ibiblio.org/maven/ant/jars/ant-1.

5.jar

qdox-Extension-Name: qdox

qdox-Implementation-Version: 1.5

qdox-Implementation-URL: http://www.ibiblio.org/maven/qdox/jars/qdox-1.

5.jar

commons-attributes-api-Extension-Name: commons-attributes-api

commons-attributes-api-Implementation-Version: 2.2

commons-attributes-api-Implementation-URL: http://www.ibiblio.org/maven/commons-attributes/jars/commons-attributes-api-2.2

.jar

javadoc-Extension-Name: javadoc

javadoc-Implementation-Version: 1.4

javadoc-Implementation-URL: http://www.ibiblio.org/maven/javadoc/jars/javadoc-1.4

.jar

Implementation-Vendor-Id: org.apache

X-Compile-Source-JDK: 1.4

X-Compile-Target-JDK: 1.4

这里的URL后面的值被换行符隔开了,显然,如果让我们自己,是不会这么干的。于是,做修改如下:

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.5.3 

Created-By: Apache Maven

Built-By: hen

Package: org.apache.commons.attributes.compiler

Build-Jdk: 1.4.2_05

Extension-Name: commons-attributes-compiler

Specification-Title: Attribute Compiler

Specification-Vendor: The Apache Software Foundation

Implementation-Title: org.apache.commons.attributes.compiler

Implementation-Vendor: The Apache Software Foundation

Implementation-Version: 2.2

Extension-List: ant qdox commons-attributes-api javadoc

ant-Extension-Name: ant

ant-Implementation-Version: 1.5

ant-Implementation-URL: http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar

qdox-Extension-Name: qdox

qdox-Implementation-Version: 1.5

qdox-Implementation-URL: http://www.ibiblio.org/maven/qdox/jars/qdox-1.5.jar

commons-attributes-api-Extension-Name: commons-attributes-api

commons-attributes-api-Implementation-Version: 2.2

commons-attributes-api-Implementation-URL: http://www.ibiblio.org/maven/commons-attributes/jars/commons-attributes-api-2.2.jar

javadoc-Extension-Name: javadoc

javadoc-Implementation-Version: 1.4

javadoc-Implementation-URL: http://www.ibiblio.org/maven/javadoc/jars/javadoc-1.4.jar

Implementation-Vendor-Id: org.apache

X-Compile-Source-JDK: 1.4

X-Compile-Target-JDK: 1.4

重新打成jar包,添加到项目lib中,启动运行,一切OK!

     可是,以前写定时器也没遇到这种情况啊,我想这跟spring的版本有关系吧;今天用的spring2.0,可是谁把MANIFEST.MF中的URL弄错的呢?我想不应该是官方的bug吧,可能是我不是在官网上下的spring开发包,有机会看看官网上是否也是这个样子。不管怎么说,项目还是在波澜不惊中顺利进行。。。

 严重: action: null

java.lang.ClassNotFoundException: org.springframework.web.struts.ContextLoaderPlugIn

缺少spring.jarspring-webmvc-struts.jar

java.lang.NoClassDefFoundError: 

Could not initialize class net.sf.cglib.proxy.Enhancer

SSH 类库问题 java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer 

2009-09-16 02:15 

由MyEclipse自动导入的Spring,Hibernate,Struts 类库 

发布到Tomcat发现问题: 

java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer 

随之 sessionFactory bean 也就创建失败 

究其原因是 cglib-2.1.3.jar 与 cglib-nodep-2.1_3.jar 这两个包冲突, 

删除 cglib-2.1.3.jar 

保留 cglib-nodep-2.1_3.jar 

要用 cglib-nodep-2.1_3.jar , 对应 spring 版本2.5 

Attribute value request.getAttribute("keyWord") is quoted with " which must be escaped when used within the value 

遇到这样的问题在网上找了解决方案现总结2点:

解决以上问题有两种解决方案:

 

方案一

 

   <jsp:include page="split_page.jsp">

    <jsp:param name="jspUrl" value="<%=jspUrl%>" />

    <jsp:param name="lineSize"

     value="<%=request.getAttribute("lineSize")%>" />

    <jsp:param name="searchFlag" value="T" />

   </jsp:include>

这里,在 value 中只是使用了 URL 而已。 

然后报错: 

Attribute value request.getAttribute("lineSize") is quoted with " which must be escaped when used within the value

啊,无语,在另一个页面中这么写就没错啊? 

Google。 

发现说是什么 apache 升级到 6.0 后出现的 bug。 

详情见: 

[#MMB-1706] quoted must be escaped - MMBase 

然后跟踪链接,这里说的很详细了: 

Possible user code changes required when we upgrade to Tomcat 6.0.18 

按照上面的说法,这么改写: 

 <jsp:include page="split_page.jsp">

    <jsp:param name="jspUrl" value="<%=jspUrl%>" />

    <jsp:param name="lineSize"

     value='<%=request.getAttribute("lineSize")%>' />

    <jsp:param name="searchFlag" value="T" />

 </jsp:include>

其实只是把 value="" 改成 value=''。 

 

方案二

 

把代码改成

   <jsp:include page="split_page.jsp">

    <jsp:param name="jspUrl" value="<%=jspUrl%>" />

    <jsp:param name="lineSize"

     value="<%=request.getAttribute(/"lineSiz/")%>" />

    <jsp:param name="searchFlag" value="T" />

   </jsp:include>

 

虽然在编辑器中会显示有错  但是运行起来是没有问题,tomcat版本的问题。

Mysql编写过程、函数、包、触发器

mysql 的sql语句如下:

mysql> delimiter //

    -> create trigger sitedata_ins2

    -> before insert on user

    -> for each row

    -> Begin

    -> If not exists(select 1 from user_data where d_id=new.id) then

    -> insert into user_data(d_id,d_name) values(new.id,new.name);

    -> END IF;

    -> end;//

    -> delimiter ;

    

或者简单一点:

mysql> delimiter //

    -> create trigger sitedata_ins2

    -> before insert on user

    -> for each row

    -> Begin

    -> insert into user_data(d_id,d_name) values(new.id,new.name);

    -> end;//

    -> delimiter ;

二种方法都可以,建议你用第一种

org.apache.tomcat.dbcp.dbcp.SQLNestedException

Cannot get a connection, pool error Timeout waiting for idle 

object

在使用tomcat的JNDI配置数据库连接时,如果没有使用想proxool,池c3p0这样的连接池组件时,tomcat将默认使用tomcat容器内建的DHCP连接池组建。

我的jndi配置如下

    <Resource

      name="jdbc/NEWDB"

      type="javax.sql.DataSource"

      username="APDEV"

      password="123456"

      driverClassName="net.sourceforge.jtds.jdbcx.JtdsDataSource"

      maxIdle="2"

      maxWait="5000"

      url="jdbc:jtds:sqlserver://172.18.127.129:1433/NEWDB"

      maxActive="4"

   />

为了在开发阶段尽可能的暴露是否存在连接未完全释放的问题,将maxActive和maxIdle参数都设置的比较小。

有一种情况就是,如果某个页面存在大量的数据库查询操作(例如:此页面加载时将要建立4个connection),那么当我在此页面频繁的刷新页面时,将会抛出异常

 org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object

经过调查发现,抛出此异常的原因为连接池泄漏,也就是再也无法从连接池中获取有效的数据库连接。

频繁的刷新页面导致上一次获取的connection还没有得到有效释放,下一次的connection请求已经到达,如是刷新多次后导致池资源耗尽,即所谓的连接池泄漏。

   而且,在此种情况下,最糟糕的是异常发生后导致整个服务向连接池发起connection请求都将一直抛出如上异常,无法恢复到正常状态。服务宕机,必须重启tomcat才能恢复,这真是个可怕的事情。

如果有的功能可以正常使用jndi,有的不行,那么说明你的配置是没有问题的。

问题可能是代码中,conn使用后没有正常关闭,引起jndi连接池泄漏导致。

解决的办法就是查到相关代码,在finnally中把conn close掉。

如果没有任何功能可以使用jndi,那再去查jndi的配置和Context配置。

改个语法错误function document.onreadystatechange() 

document.onreadystatechange= function(){

    .....

}

function document.onreadystatechange()

{

  if (YInitializedreturn;

  YInitialized = true;

  var i, s, curr;

  for (i=0; i<document.body.all.length;i++)

  {

    curr=document.body.all[i];

    if (curr.className == "yToolbar")

    {

      InitTB(curr);

      yToolbars[yToolbars.length] = curr;

    }

  }

  DoLayout();

  window.onresize = DoLayout;

  Composition.document.open()

  Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");

  Composition.document.close()

  Composition.document.designMode="On"

}

修改成为

//function document.onreadystatechange()

document.onreadystatechange= function()

{

  if (YInitializedreturn;

  YInitialized = true;

  var i, s, curr;

  for (i=0; i<document.body.all.length;i++)

  {

    curr=document.body.all[i];

    if (curr.className == "yToolbar")

    {

      InitTB(curr);

      yToolbars[yToolbars.length] = curr;

    }

  }

  DoLayout();

  window.onresize = DoLayout;

  Composition.document.open()

  Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");

  Composition.document.close()

  Composition.document.designMode="On"

}

Myeclipse 10.0优化

1、老是弹出Quick update error 、关闭myeclipseQuick Update自动更新功能 

     这个问题的解决办法是关闭自动更新 

     Windows > Preferences > MyEclipse Enterprise Workbench > 

Community Essentials, 

     把选项 "Search for new features on startup"的前勾去掉即可。 

、关闭updating indexes 

      Window > Preferences > Myeclipse >Enterprise Workbench > 

Maven4Myeclipse > Maven> 

      禁用Download repository index updates on startup 。 

、关闭MyEclipse的自动validation 

validation有一堆,什么xmljspjsfjs等等,我们没有必要全部都去自动

校验一下, 

      只是需要的时候才会手工校验一 下,速度立马提升好几个档次 

      windows > perferences > myeclipse > validation 

      将Build下全部勾取消 

      如果你需要验证某个文件的时候,我们可以单独去验证它。方法是: 

      在需要验证的文件上右键 -> MyEclipse -> Run   Validation 。 

4、 启动优化,关闭不需要使用的模块 

      一个系统20%的功能往往能够满足80%的需求,MyEclipse也不例外,我们在大多数时候只需要20%的系统功能, 

     所以可以将一些不使用的模块禁止 加载启动。 

     Window > Preferences > General > Startup andy Shutdown 在这里列

出的是MyEclipse启动时加载的模块 

     我这里只让它加载tomcat5 勾选 MyEclipse EASIE Tomcat 5 。 

     怎样才能知道哪些启动项有用呢?我现在把我知道的启动项用处说一下,还有很多不

懂的, 

     希望大家懂的回复在下面    啊: 

          WTP :一个跟myeclipse差不多的东西,主要差别是 WTP 是免费的,如果使

myeclipse,这个可以取消 

          Mylyn:组队任务管理工具,类似于 CVS ,以任务为单位管理项目进度,没用

到的可以取消 

          Derby:一种保存成 jar 形式的数据库,我没用到,取消 

          一大排以 MyEclipse EASIE 打头的启动项:myeclipse 支持的服务器,只

选自己用的,其他取消, 

         比如我只选了    tomcat 。 

、去掉MyEclipse的拼写检查(如果你觉的有用可以不去) 

      拼写检查会给我们带来不少的麻烦,我们的方法命名都会是单词的缩写,他也会提示

有错, 

      所以最好去掉,没有多大的用处 

      Window > perferences > General > Editors > Text Editors > 

Spelling > Enable spell checking复选框的勾选去掉。 

、去掉MyEclipse繁杂的自带插件自动加载项 

      Window > perferences > General > Startup and Shutdown > 

Plug-ins activated on startup 

      中的复选框有选择性的勾   选去掉。 

、修改MyEclipse编辑JSP页面时的编辑工具 

      Window > perferences > General > Editors > File Associations 

      在File types 中选择 *.jsp > Associated editors 中将"MyEclipse JSP Editor"设置为默认。 

、修改MyEclipse安装目录的eclipse.ini文件,加大JVM的非堆内存 

      具体内容如下: 

     -clean 

     -showsplash 

     com.genuitec.myeclipse.product.ide 

     –launcher.XXMaxPermSize 

     256m 

     -vmargs 

     -Xms128m 

     -Xmx512m 

     -Duser.language=en 

     -XX:PermSize=128M 

     -XX:MaxPermSize=256M 

     把下面的那个 -XX:MaxPermSize 调大,比如 -XX:MaxPermSize=512M,再把 -XX:PermSize 调成跟 

     -XX:MaxPermSize一样大

         MyEclipse 8.0 GA 版本,启动后发现要等一会才出来,并没有看见启动画面,我们只需要在myeclipse.ini 里面配置一下就可以了。 

代码如下:

 view plaincopy to clipboardprint?

-Dosgi.splashLocation=../Common/plugins/com.genuitec.myeclipse.product8_8.0.0.me200911192201/splash.bmp    

-Dosgi.splashLocation=../Common/plugins/com.genuitec.myeclipse.product8_8.0.0.me200911192201/splash.bmp

原创粉丝点击