Connect tomcat to the MySQL database in Ubuntu

Source: Internet
Author: User

In Linux, configuring MySQL Databases on Tomcat is not as simple as windows... Therefore, it is worth writing down a record for future reference.

1. Download and install MySQL

Installing MySql in Ubuntu is very simple. You only need:

 
Sudo apt-Get install mysql-Server

During the installation process, you will be asked to set the user name and password. Mine is root and root.

2. Download JDBC

Go to http://www.mysql.com/downloads/download MySQL connectors for Java

Decompress the package and place the mysql-connector-java-5.1.24-bin.jar in the % atat_home/lib directory.

3. Configure Tomcat

Open the % atat_home/CONF/context. xml file,

Add the followingCode:

<Resource Name = "JDBC/mysqlds" auth = "Container" type = "javax. SQL. datasource "maxidle =" 30 "maxwait =" 3000 "maxactive =" 10 "username =" root "Password =" root "driverclassname =" org. gjt. mm. mySQL. driver "url =" JDBC: mysql: // localhost/LC "> </resource>

Note that username and password are set to the value set during MySQL installation.

Then you can use JSP code to perform database operations.

However, there is still a problem, that is, when we operate MySQL on the terminal, the error "MySQL access denied for user" will be reported.

The solution is to enter:

 
Sudo mysql-uroot-P

Then enter the password of the root user to access the MySQL database.

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.