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/jdk1.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:/j2sdk1.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:

 

 

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

     

          

           Insert

     

     

      <%

      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() );

      }   

      %>

     

 

 

 

 

 

 

 

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:

 

 

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

     

          

           Update

     

     

      <%

      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() );

      }   

      %>

     

 

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:

 

 

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

     

          

           Delete

     

     

      <%

      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() );

      }   

      %>

     

 


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 :~

 

你可能感兴趣的:(jdk Tomcat MySql 环境变量地的配置)