Jsp+tomcat+mysql&sevlet&javabean Configuration Whole process

Source: Internet
Author: User
Tags anonymous connect mysql mysql client variables stmt mysql command line mysql database
js|mysql| process

In the process of configuring JSP development environment will encounter a lot of problems, thanks to the experience of many predecessors on the Internet, the author cl41 JSP connection MySQL database introduction and author Saulzy MySQL learning notes and other articles for me is simply snow to send carbon, In order to help beginners like me here summed up a lot of the author's experience, thank them very much for their selfless dedication, but also hope that more people to carry forward this spirit, hehe, again to the author of the reference article to express the most lofty respect!
The following software download link address can not be displayed, please go directly to the official website to download it!

Software downloads
Mysql
Download version: Mysql-4.1.13-win32.zip (Windows downloads)
Http://dev.mysql.com/downloads/mysql/4.1.html

JDBC Driver
Download version: Mysql-connector-java-3.1.10.zip
Http://dev.mysql.com/downloads/connector/j/3.1.html

Download J2SDK
Download version: Jdk-1_5_0_04-windows-i586-p.exe
http://java.sun.com/j2se/1.5.0/download.jsp

Download Tomcat
Download version: Jakarta-tomcat-5.5.9.exe
http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi

Install, configure J2SDK:

Perform J2SDK setup, install by default, or customize the path, but modify the following configuration

Configure J2SDK:

To configure environment variables:

My Computer-> Properties-> the advanced-> environment variable-> system variable add the following environment variables:
Java_home=c:\program files\java\jdk1.5.0_04
Classpath=%java_home%\lib\dt.jar;%java_home%\lib\tools.jar;
Path=%java_home%\bin;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem

Write a simple Java program to test whether the J2SDK has been installed successfully:
public class Hello
{
public static void Main (String args[])
{
System.out.println ("Hello");
}
}

Save the program as a file with a file name of Hello.java.

Open a Command Prompt window and enter the directory where Hello.java is located, type the following command
Javac Hello.java
Java Hello
At this point if the print out Hello is installed successfully, if not printed out this sentence, carefully check the above configuration is correct.
Note The System Folder option should determine "Hide extensions for known file types" not checked (My computer? tools? view)

Install, configure Tomcat
Perform the Tomcat installer, install by default, or customize the path, but modify the following configuration

My Computer-> Properties-> Advanced-> environment variable-> system variable add the following environment variables
Catalina_home=c:\program Files\apache Software Foundation\tomcat 5.5
Catalina_base=c:\program Files\apache Software Foundation\tomcat 5.5

Modify the Classpath in the environment variable to add the Servlet-api.jar under the Tomat installation directory to Classpath,
The modified classpath is as follows:
Classpath=%java_home%\lib\dt.jar;%java_home%\lib\tools.jar; C:\Program Files\apache Software Foundation\tomcat 5.5\common\lib\servlet-api.jar;

Start Tomcat, access http://localhost:8080 in IE, and if you see the Tomcat Welcome page, the installation is successful.

installing MySQL
Decompress Mysql-4.1.13-win32.zip, run Setup.exe
The first thing that appears is the Installation Wizard welcome interface, click "Next" directly
Continue, select the installation type, select "Custom" Custom install, then click "Next" Next, the Custom installation interface appears
Select installation path: C:\MySQL Server 4.1 (customizable)
Click OK to return to the custom installation interface, path changed to set path
Point "Next" to start the installation
Click "Install" to start the installation
The interface to create the MySQL.com account is present when completed
If you are using MySQL for the first time, select "Create anew free mysql.com accout"
Click "Next", enter your email address and your own set of password for login mysql.com
When you are finished, click Next to enter the second step.
Fill in the name and other related information, fill out the point "Next", enter the third step
After completing the phone number, company name, and so on, click "Next",
Then there appears a preview of the information you just filled in the interface, click "Next" appears the installation completion interface
Note that there is a configuration Wizard option (Configure the MySQL Server now),
It is recommended to configure your MySQL immediately. Many say the installation of MySQL can not start after the reason is not configured MySQL.
Click "Finish" to complete the installation and start to configure MySQL
Click "Next" to enter the configuration Type Selection page. Select "Detailed Configuration" (Detailed configuration)
Click "Next" to enter the service Type Selection page. Choose "Developer Machine" (developer machine) so that the resources of the system will not be much
Click "Next" to enter the database Usage Selection page. Select "Multifunctional Database"
Click "Next" to enter the InnoDB data storage Location page
Do not change the settings, directly in the installation path installation directory, and then click "Next", choose the number of concurrent MySQL connection
Select "Manual Setting", set to 100 (set as appropriate, as required)
Click "Next" to configure MySQL's port in the TCP/IP communication environment to select the default 3306 port.
Click "Next" to select the character settings in MySQL
Note that the choices here will affect whether you can use Chinese in MySQL. Select gb2312 character set to support Simplified Chinese
Click "Next" to set Windows service options
Note that the choice here is critical.
"Install as Windows Service" must be checked, this is the MySQL as Windows services run.
"Service Name" is the default "MySQL"
The following "Launch the MySQL Server automatically" must be checked, so that when Windows starts, MySQL will automatically start the service, or you will manually start MySQL.
Many people say that after installing MySQL, unable to start, cannot connect, there are 10061 errors, the reason is here.
Click "Next" to set the login password for root account root
"Modify security Settings" is to set the root account password, enter your password can be set.
"Create a Anonymous account" is the creation of an anonymous accounts, which will cause unauthorized users to access your database illegally, there are security concerns, the proposal does not check.
Point "Next", MySQL Configuration wizard will be based on all the settings above you to configure MySQL, so that the operation of MySQL to meet your needs
Click "Execute" to start configuration, when "service started successfully", the description of your configuration completed, MySQL service started successfully
Point "Finish" completed, the entire MySQL configuration completed, the rest is to use MySQL client connection MySQL server, and then used.


To install the JDBC driver:
Decompression Mysql-connector-java-3.1.10.zip
will be using Mysql-connector-java-3.1.10-bin-g.jar and Mysql-connector-java-3.1.10-bin.jar.

Configuration
The MYSQLFORJDBC subdirectory is established under the C:\Program Files\java directory, which will be mysql-connector-java-3.1.10-bin.jar into the directory
Enter the C:\Program files\java\jdk1.5.0_04\lib directory to copy Mysql-connector-java-3.1.10-bin-g.jar to the directory
Then configure Classpath, append%java_home%\lib\mysql-connector-java-3.1.10-bin-g.jar; C:\Program Files\java\mysqlforjdbc\mysql-connector-java-3.1.10-bin.jar; Go to the environment variable
After appending the environment variables are as follows:
Classpath=%java_home%\lib\dt.jar;%java_home%\lib\tools.jar; C:\Program Files\apache Software foundation\tomcat5.5\common\lib\servlet-api.jar;%java_home%\lib\ Mysql-connector-java-3.1.10-bin-g.jar; C:\Program Files\java\mysqlforjdbc\mysql-connector-java-3.1.10-bin.jar;
The purpose of this configuration is to have the Java application find the driver to connect to MySQL.


View and start the MySQL service
After installing MySQL under Windows XP, it has started the service automatically and has a shortcut connection to its client in the Start menu
Can be viewed through the Windows Service Manager. "Start"-"Run", enter "Services.msc", carriage return.
Windows Service Manager pops up, and then you can see the service item with the service name "MySQL", with the right labeled "Started"
In the Start menu-All Programs-mysql-mysql Server 4.1-mysql Command line client connects with shortcuts to clients
Enter the setup is the password you can


Use of the database

After MySQL is installed, in the Start menu-All Programs-mysql-mysql Server 4.1-mysql Command line client uses the client's shortcut connection
Enter the password set at installation

Basic commands for MySQL (you must have a semicolon at the end of the MySQL command line edit after each input command)
Display database: show databases;
Using database: Use database name;


Build a library
Build a database in MySQL, and a table in the database about
Command: Create database A;

Set permissions for a database (user and password)
Command: Grant all privileges on first.* to Test@localhost identified by "123456";
When you're done with this command, you can only do this with the user name: Test, Password: 123456 When you log on, so that you avoid using the root
Enter command: Use A;
Use of the A-database;

To build a table in the I-Library
Command: CREATE table about (ID int (8) Primary key,name varchar (10));

In the table if the data:
Command: INSERT into about values (' xyw1026 ', ' Laojiang ');

Exit
Command: Exit


JSP connection MySQL
C:\Program files\apache Software Foundation\tomcat5.5\webapps directory to create subdirectories MyApp
Enter the C:\Program files\apache Software Foundation\tomcat5.5\webapps\myapp Directory
Write a file in Notepad to save as first.jsp
The code is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<body>
<%class.forname ("Org.gjt.mm.mysql.Driver"). newinstance ();
String url = "jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useunicode=true& Characterencoding=8859_1 "
The name of your database
Connection conn= drivermanager.getconnection (URL);
Statement stmt=conn.createstatement (resultset.type_scroll_sensitive,resultset.concur_updatable);
String sql= "select * from";
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {%>
Your first field content is: <%=rs.getstring (1)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>

[1] [2] Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.