Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213871
  • 博文数量: 39
  • 博客积分: 891
  • 博客等级: 准尉
  • 技术积分: 452
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-08 18:24
文章分类

全部博文(39)

文章存档

2012年(11)

2011年(28)

我的朋友

分类: Java

2011-12-08 09:37:17

   我只是新手, 这篇文章把我前面的努力写的非常的简单明了,没有像我一样赘述流程.
    这里插一点题外话,人的能力是在挑战中不断提升的,以前玩<魔兽世界>的时候,副本开荒,人还是那些人,装备还是那些装备,经历了数天的开荒成功击倒boss之后,以后这个boss就是小菜一碟了.技术也有这样一个临界点,总是感觉力不从心,但是在一定的积累之后,面对问题就会轻松许多.什么都有一道坎,不过就是一座山,过了就是垫脚石.努力吧. 
    需要安装连接mysql的jar.  在mysql官网有下载.  mysql-connector-java-5.1.18.zip  将其解压,把其中的mysql-connector-java-5.1.17-bin.jar 放到tomcat的lib目录下.
   写一个测试脚本, 不是我写的.来自这篇最开始的链接.
    中间有一个插曲,我忘记了自己mysql的密码了,最近记性比较差.顺便插入下mysql重设密码的办法.
[root@doita bin]#./mysqld_safe --skip-grant-tables &
[1] 7501
[root@doita bin]#111208 03:53:05 mysqld_safe Logging to '/opt/mysql-5.1.60/var/doita.err'.
111208 03:53:05 mysqld_safe Starting mysqld daemon with databases from /opt/mysql-5.1.60/var

[root@doita bin]#./mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.60-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Database changed
mysql> update user set password=password("new_passwd")where user="root";
Query OK, 3 rows affected (0.07 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)

下面是那段测试代码, 密码要填成自己的.
  1. <%@ page language="java" %>
  2. <%@ page import="com.mysql.jdbc.Driver" %>
  3. <%@ page import="java.sql.*" %>
  4. <%
  5. String driverName="com.mysql.jdbc.Driver";
  6. String userName="root";
  7. String userPasswd="123"; 
  8. String dbName="test";
  9. String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
  10. Class.forName("com.mysql.jdbc.Driver").newInstance();
  11. try
  12. {
  13.         Connection connection=DriverManager.getConnection(url);
  14.         out.println(" O K !");
  15.         connection.close();
  16. }
  17. catch( Exception e )
  18. {
  19.         out.println( "connent mysql error:" + e );
  20. }
  21. %>
在测试的时候出现了错误,因为classpath的问题,重启tomcat时发现的:
[root@doita bin]#./catalina.sh start
Using CATALINA_BASE:   /opt/apache-tomcat-6.0.33
Using CATALINA_HOME:   /opt/apache-tomcat-6.0.33
Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.33/temp
Using JRE_HOME:        /opt/jdk1.6.0_29
Using CLASSPATH:       /opt/apache-tomcat-6.0.33/bin/bootstrap.jar
 
没有系统的classpath并未被导入,java和tomcat 的lib并没有加入其中,
我的解决方案是在
catalina.sh 中添加变量值 (红色黑体),但是这是一个很糟糕的办法,配置文件里都有提到(蓝字).但我现在的能力也就是能调到能用.... 可能加载太多jar,会使服务器速度变慢,更容易引起引用混淆吧?

  1. # Ensure that any user defined CLASSPATH variables are not used on startup,
  2. # but allow them to be specified in setenv.sh, in rare case when it is needed.
  3. CLASSPATH=$CLASSPATH





  
  
  
阅读(1888) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~