Tomcat 连接数据库

Tomcat  需要论坛,博客一类的系统,然后这个系统去连接后台的数据库

[root@localhost ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[root@localhost ~]# ls /web/webapp/SLSaleSystem/
logs  META-INF  statics  WEB-INF
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml
<Context docBase="/web/webapp/SLSaleSystem" path="" reloadable="flase" >
</Context>
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh 
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh

安装配置数据库

[root@localhost ~]# yum -y install mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> create database slsaledb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on slsaledb.* to admin@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Tomcat 连接数据库   (因为库是空的,因此需要导入 “slsaledb-2014-4-10.sql”)

主要是填写IP地址,用户名,密码

[root@localhost ~]# mysql -uroot < slsaledb-2014-4-10.sql
[root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.200.117:3306/slsaledb?useUnicode=true&characterEncoding=UTF-8
uname=admin
password=123456
minIdle=10
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh 
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
原文地址:https://www.cnblogs.com/2567xl/p/11574565.html