安裝環境為:CentOS-6.5-x86_64-minimal
安裝mysql
sudo yum install mysql mysql-server mysql-devel
install_mysql.png
creat_db_tomcat.png
grant_db_tomcat.png
安裝jdk和tomcat
建立安裝jdk和tomcat的檔案夾
mkdir_java_tomcat.png
cp_jdk_tomcat_to_opt.png
add_java_env.png
java_version.png
簡單配置tomcat
config_tomcat1.png
config_tomcat2.png
啟動tomcat
start_tomcat.png
see_tomcat_index.png
連接配接資料庫
tomcat_copy_mysql_driver.png
[[email protected] ~]$ vim /opt/tomcat/apache-tomcat-8.0.36/webapps/ROOT/a.jsp
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