安装环境为:CentOS-6.5-x86_64-minimal
安装mysql
sudo yum install mysql mysql-server mysql-devel
安装jdk和tomcat
-
创建安装jdk和tomcat的文件夹
mkdir_java_tomcat.png
- 下载安装包并解压安装
jdk包可在http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载
tomcat包可在http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz 下载
download_tomcat.png
简单配置tomcat
config_tomcat1.png config_tomcat2.png启动tomcat
start_tomcat.png see_tomcat_index.png连接数据库
驱动可在http://dev.mysql.com/downloads/connector/j/ 下载
[reber@WYB ~]$ vim /opt/tomcat/apache-tomcat-8.0.36/webapps/ROOT/a.jsp
<%@page contentType="text/html;charset=utf-8" import="java.sql.*" %>
<%
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/tomcat"; //数据库web
String user = "tomcat";
String password = "123456";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
out.println("数据库连接成功!");
conn.close();
}
catch(ClassNotFoundException e) {
out.println("找不到驱动程序");
e.printStackTrace();
}
catch(SQLException e) {
e.printStackTrace();
}
%>
tomcat_conn_mysql.png
网友评论