天天看點

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

安裝環境為:CentOS-6.5-x86_64-minimal

安裝mysql

sudo yum install mysql mysql-server mysql-devel

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

install_mysql.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

creat_db_tomcat.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

grant_db_tomcat.png

安裝jdk和tomcat

建立安裝jdk和tomcat的檔案夾

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

mkdir_java_tomcat.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

cp_jdk_tomcat_to_opt.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

add_java_env.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

java_version.png

簡單配置tomcat

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

config_tomcat1.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

config_tomcat2.png

啟動tomcat

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

start_tomcat.png

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

see_tomcat_index.png

連接配接資料庫

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

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();

}

%>

linux jsp配置mysql_Linux下搭建Tomcat+MySQL+JSP

tomcat_conn_mysql.png