jdk Tomcat MySql 环境变量地的配置

Tutorial

 

1. Preparation. 2

2. Install JDK. 3

3. Install TOMCAT. 5

4. Install MySQL & MySQLFront 10

5. Database Creating & How to import data. 12

6. Installing Project & Login. 12

7. Insert, update and delete data. 12

7.1 Insert 12

7.2 Update. 17

7.3 Delete. 19


1. Preparation

Make sure you have got all the files & software in your hand.

 

Here’s a list:

jdk-1_5_0_01-windows-i586-p.exe

jakarta-tomcat- 5.0.28 .exe

MySql.exe

MySQL-Front_Setup.exe

mysql-connector-java- 3.1.11 -bin.jar


2. Install JDK

Double click jdk-1_5_0_01-windows-i586-p.exe to install JDK

Set the environment variable:

Right click我的电脑”==》属性==》高级==》环境变量==》新建...

 


 

 

 

 

variable name

variable value

JAVA_HOME

C:/Java/jdk 1.5.0 _04

PATH

.;C:/Java/jdk1.5.0_04/bin

CLASSPATH

.;C:/Java/jdk1.5.0_04 /lib/tools.jar;


3. Install TOMCAT
You can view 01-Tomcat-install&start.avi to learn how to install, tart and stop Tomcat.


 Double click jakarta-tomcat- 5.0.28 .exe to install Tomcat.


Set connector port, user name and password.


 

 

Select the path of JVM



  
  After starting Tomcat, there will be an icon on the system bar.


  Right click mouse on the icon, and you will view something like configure

 

Click “Configure”, add “-Djava.home=d:/j2sdk 1.4.2 _ 04” in “Java Option”,

 


 

 


Testing

 

Before testing, you need to set the environment variable again:

 

variable name

variable value

CATALINA_HOME

d:/Tomcat 5.0

CLASSPATH

.;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tool.jar;%JAVA_HOME%/lib/tools.jar;%CATALINA_HOME%/common/lib/servlet-api.jar;%CATALINA_HOME%/common/lib/jsp-api.jar

 


Restart Tomcat, start up the IE browser and input
http://localhost:8080, then you will view the following information.


Notice

If you want to connect MySQL throw Tomcat, you must copy mysql-connector-java- 3.1.11 -bin.jar to Tomcat 5.0/common/lib, the restart Tomcat.

 

You can view 01-Tomcat-install&start.avi to learn how to install, start and stop Tomcat.

 


4. Install MySQL & MySQLFront

 

You can view 02-MySQL-install.avi, 03-MySQLFront-install&start.avi to learn how to install and start MySQL & MySQLFront.

 

 

You can set the user name at will.

 

 

Set the server as localhost

 

 

 

Set the user as “root”.

Set the password at will.

Select database “test”.

 

You can view 02-MySQL-install.avi, 03-MySQLFront-install&start.avi to learn how to install and start MySQL & MySQLFront.

5. Database Creating & How to import data

 

You can view 04-MySQL-Database creating&import.avi to learn how to create database and how to import data. Here we use the database file “caesh”.

 

6. Installing Project & Login

 

You can view 05-Installing Project & Login.avi to learn how to install and login into a project.

 

7. Insert, update and delete data

7.1 Insert

Create a database named “student”, then create a new table named “student” too in the new database.

 

Add three fields named stuID, stuNM, stuAP in the new table.

 

Each field type should be “VarChar”, the length should be “ 255”

 

Then you can create a jsp file “Student_Insert.jsp”

 

The content is as following:

 

Student_Insert.jsp:

 

<!--     

      Project:Redcode 1.5

      Name:   Student_Insert.jsp

      Author: Sijiangong

      Date:     05/05/2006

      Description: This page is used to insert data.

     

      Modify Date: 06/05/2006

      Modified By: Sijiangong

      Description: Coding 

-->

 

<%@ page import="java.sql.*"%>

<html>

      <head>

           <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

           <title>Insert</title>

      </head>

      <body>

      <%

      String strNumber = "0581490025";           //student number

      String strName = "GaoXi";                      //student name      

      String strApartment = "SoftwareSchool";  //student apartment     

     

      Connection con = null;                          //connection with the database

      String strSql = null;                              //SQL querry

      Statement stmt = null;

      ResultSet rs = null;       

      %>

      <%

      try{

           // to connect the database       

           Class.forName("com.mysql.jdbc.Driver");

           con = DriverManager.getConnection

("jdbc:mysql://localhost:3306/student?user=root&password=123");

 

           strSql = "INSERT INTO student VALUES

('"+strNumber+"','"+strName+"','"+strApartment+"')";

           stmt = con.createStatement();

           stmt.execute(strSql);

           out.println("Data inserted"); 

           stmt.close();

           con.close();

      } catch( Exception e ) {

           System.out.println( e.toString() );

      }   

      %>

      </body>

</html>

 

 

 

 

 

 

 

Copy this file to “Tomcat 5.0/webapps/ROOT”, then input “http://localhost:8080/Student_Insert.jsp“ into the IE address bar, you will view the following page:

 

Check the database, you will find the newly inserted data.

 


7.2 Update

Create a jsp file “Student_Update.jsp”

 

The content is as following:

 

Student_Update.jsp:

 

<!--     

      Project:Redcode 1.5

      Name:  Student_Update.jsp

      Author: Sijiangong

      Date:     05/05/2006

      Description: This page is used to update data.

     

      Modify Date: 06/05/2006

      Modified By: Sijiangong

      Description: Coding 

-->

 

<%@ page import="java.sql.*"%>

<html>

      <head>

           <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

           <title>Update</title>

      </head>

      <body>

      <%

      String strNumber = "0581490025";           //student number

      String strName = "COOSEKI";            //student name      

      String strApartment = "SoftwareSchool";  //student apartment     

     

      Connection con = null;                          //connection with the database

      String strSql = null;                              //SQL querry

      Statement stmt = null;

      ResultSet rs = null;       

      %>

      <%

      try{

           // to connect the database       

           Class.forName("com.mysql.jdbc.Driver");

           con = DriverManager.getConnection

                 ("jdbc:mysql://localhost:3306/student?user=root&password=123");

           strSql = "UPDATE student SET stuNM = '"+strName+"' WHERE stuID = '"+strNumber+"'";

           stmt = con.createStatement();

           stmt.executeUpdate(strSql);

           out.println("Data updated"); 

           stmt.close();

           con.close();

      } catch( Exception e ) {

           System.out.println( e.toString() );

      }   

      %>

      </body>

</html>

 

Copy this file to “Tomcat 5.0/webapps/ROOT”, then input “http://localhost:8080/Student_Update.jsp“ into the IE address bar, you will view the following page:

 

 


The data has been changed

 

 

7.3 Delete

Create a jsp file “Student_Delete.jsp”

 

The content is as following:

 

<!--     

      Project:Redcode 1.5

      Name:   Student_Delete.jsp

      Author: Sijiangong

      Date:     05/05/2006

      Description: This page is used to delete data.

     

      Modify Date: 06/05/2006

      Modified By: Sijiangong

      Description: Coding 

-->

 

<%@ page import="java.sql.*"%>

<html>

      <head>

           <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

           <title>Delete</title>

      </head>

      <body>

      <%

      String strNumber = "0581490025";                 //student number

      String strName = "GaoXi";                           //student name      

      String strApartment = "SoftwareSchool";        //student apartment     

     

      Connection con = null;                               //connection with the database

      String strSql = null;                                    //SQL querry

      Statement stmt = null;

      ResultSet rs = null;       

      %>

      <%

      try{

           // to connect the database       

           Class.forName("com.mysql.jdbc.Driver");

           con = DriverManager.getConnection

                 ("jdbc:mysql://localhost:3306/student?user=root&password=123");

 

           strSql = "DELETE FROM student WHERE stuID = '"+strNumber+"'";

           stmt = con.createStatement();

           stmt.execute(strSql);

            out.println("Data deleted"); 

           stmt.close();

           con.close();

      } catch( Exception e ) {

           System.out.println( e.toString() );

      }   

      %>

      </body>

</html>

 


Copy this file to “Tomcat 5.0/webapps/ROOT”, then input “http://localhost:8080/Student_Insert.jsp“ into the IE address bar, you will view the following page:

 

The record has been deleted

 

by Si :~

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值