JSP环境搭建第三步、MYSQL的安装
1)、安装MYSQL
- [root@linuxas Server]# rpm -vih perl-DBI-1.52-1.fc6.i386.rpm
- warning: perl-DBI-1.52-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
- Preparing... ########################################### [100%]
- 1:perl-DBI ########################################### [100%]
- [root@linuxas Server]# rpm -vih mysql-5.0.22-2.1.i386.rpm
- warning: mysql-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
- Preparing... ########################################### [100%]
- 1:mysql ########################################### [100%]
- [root@linuxas Server]# rpm -vih perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
- warning: perl-DBD-MySQL-3.0007-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
- Preparing... ########################################### [100%]
- 1:perl-DBD-MySQL ########################################### [100%]
- [root@linuxas Server]# rpm -vih mysql-server-5.0.22-2.1.i386.rpm
- warning: mysql-server-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
- Preparing... ########################################### [100%]
- 1:mysql-server ########################################### [100%]
2)、启动服务
- [root@linuxas ~]# service mysqld start
初始化 MySQL 数据库:
- Installing all prepared tables
- Fill help tables
- To start mysqld at boot time you have to copy support-files/mysql.server
- to the right place for your system
- PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
- To do so, start the server, then issue the following commands:
- /usr/bin/mysqladmin -u root password 'new-password'
- /usr/bin/mysqladmin -u root -h linuxas password 'new-password'
- See the manual for more instructions.
- You can start the MySQL daemon with:
- cd /usr ; /usr/bin/mysqld_safe &
- You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
- cd sql-bench ; perl run-all-tests
- Please report any problems with the /usr/bin/mysqlbug script!
- The latest information about MySQL is available on the web at
- http://www.mysql.com
- Support MySQL by buying support/licenses at http://shop.mysql.com
[确定]
启动 MySQL: [确定]
设置登录 MySQL 的用户名和密码
- [root@linuxas ~]# mysqladmin -uroot password pwd@123
运行mysql ,并开放root用户的远程访问权限。以便调试
- use mysql
- update user set host = '%' where user = 'root' and host < > 'localhost';
- flush privileges;
- quit
JSP环境搭建第四步、JDBC的安装
1)、从官网下载安装程http://dev.mysql.com/downloads/connector/j/5.1.html下载最新文件mysql-connector-java-5.1.7.tar.gz并上传到安装目录。
2)、安装JDBC并配置tomcat
- [root@linuxas src]# tar -zxvf mysql-connector-java-5.1.7.tar.gz
- [root@linuxas src]# cp mysql-connector-java-5.1.7/mysql-connector-java-5.1.7-bin.jar /tomcat/lib/
- [root@linuxas src]# cp mysql-connector-java-5.1.7/mysql-connector-java-5.1.7-bin.jar /usr/local/src/jdk1.6.0_14/jre/lib/
JSP环境搭建第五步、测试系统环境
1)、新建数据库及表
- mysql> GRANT ALL PRIVILEGES ON *.* TO llk726@localhost IDENTIFIED BY 'pwd@123' WITH GRANT OPTION;
- mysql> create database test;
- mysql> use test;
- mysql> create table testtable(id int not null auto_increment primary key, foo varchar(25), bar int);
- mysql> insert into testtable values(null, 'hello', 12345);
2)、编写测试网页test.jsp
- [root@linuxas ROOT]# vi test.jsp
- < %@ page contentType="text/html; charset=gb2312" language="java"%>
- < %@page import="java.sql.*"%>
- < %
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String url="jdbc:mysql://localhost/test?user=llk726&password=pwd@123&useUnicode=true&characterEncoding=utf8";
- Connection conn=DriverManager.getConnection(url);
- Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- String sql="select * from testtable";
- %>
- < table border=1>
- < tr>
- < td>字段1< /td>
- < td>字段2< /td>
- < td>字段3< /td>
- < /tr>
- < %
- ResultSet rs=stmt.executeQuery(sql);
- while(rs.next()){%>
- < tr>
- < td>< %=rs.getString("ID")%> < /td>
- < td>< %=rs.getString("FOO")%> < /td>
- < td>< %=rs.getString("BAR")%> < /td>
- < /tr>
- < %}%>
- < /table>
- < %rs.close();
- stmt.close();
- conn.close();
- %>
3)、测试结果如下:
JSP的运行环境到此便搭建成功。本文出自 “键盘系人生” 博客。