在Windows 2000 Server上安装配置MySQL +Tomcat

本文介绍在Windows 2000 Server上配置MySQL和Tomcat的详细步骤。包括MySQL的安装、配置、测试,MySQL JDBC驱动的设置,Tomcat数据库连接池的配置,以及在Tomcat上对MySQL进行测试,通过创建表、插入记录和访问JSP页面查看结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备环境
参见本人上一篇文章《在Windows 2000 Server上安装配置Apache+Tomcat》
下载以下软件
1.mysql-4.0.21
2.mymanager28        //MySQL图形管理工具,很好用。中文显示不太好。                  
                                  //实现对数据库的操作和管理。

[Setup Mysql]
1.run mysql-4.0.21-win/setup.exe on c:/mysql

[Config Mysql]
1.run c:/mysql/bin/winmysqladmin.exe
2.注意my.ini文件中[mysqld]basedir内容的正确性
 [mysqld]
 basedir=c:/mysql
 
[Setup Mysql Manager]
1.run mymanager28/setup.exe

[Test Mysql]
1.Registe mysql 数据库
 user:root 
 password:空(mysql安装时指定)
2.Connect mysql
  成功标示:find table information  

[Setup Mysql JDBC driver]
1.copy mysql-connector-java-3.0.15-ga-bin.jar复制到%TOMCAT_HOME%/common/lib

[Config Tomcat 数据库连接池 for Mysql]
1.create Mysql DB:study
2.create Mysql user:test password:test
3.http://127.0.0.1:8090,进入tomcat页,用tomcat的Tomcat Administration--->Resources--->Data Sources页面添加,参数如下:
 Name: jdbc/mysql
 Data Source URL: jdbc:mysql://localhost:3306/study?autoReconnect=true&useUnicode=true&characterEncoding=GB2312
 JDBC Driver Class: com.mysql.jdbc.Driver
 ser Name:test
 Password:test
 Max. Active Connections:4
 Max. Idle Connections:2
 Max. Wait for Connection:5000
 Validation Query ://不添
4.Modify $Tomcat_HOME$/conf/server.xml, 拷贝步骤3对server.xml的修改部分到examples的context中。


[Test Mysql on Tomcat]
1.Mysql:在study中create table 表cat
   Column |         Type          | Modifiers
   -------+-----------------------+-----------
   cat_id | character(32)         | not null
   name   | character varying(16) | not null
   sex    | character(1)          |
   weight | real                  |
   Indexes: cat_pkey primary key btree (cat_id)
  插入一行纪录到CAT表中
 
2.Create file test.jsp,然后http访问这个jsp页,test.jsp代码如下
 <%@ page import="java.sql.*"%>
 <%@ page import="javax.naming.*"%>
 <%@ page import="javax.sql.*"%>
 <%
 try{
 Context initCtx = new InitialContext();
 Context ctx = (Context) initCtx.lookup("java:comp/env");
 DataSource ds = (DataSource) ctx.lookup("jdbc/mysql");
 Connection conn = ds.getConnection();
 Statement stmt = conn.createStatement();
 String strSql = " select * from cat";
 ResultSet rs = stmt.executeQuery(strSql);
 while(rs.next()){
 out.println(rs.getString(2));
 }
 }
 catch(Exception ex){
 ex.printStackTrace();
 }
 %> 
 文件保存在目录$Tomcat_HOME$/webapps/examples下
 
3. Http://127.0.0.1:8090/examples/test.jsp即可看到结果:CAT NAME。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值