tomcat+jsp+mysql

 

tomcat+jsp+mysqlphp

 

 mysql-connector-java-3.1.6.tar.gzhtml

下載地址 http://dev.mysql.com/downloads/connector/j/       (用戶名:yangzhiming@126.com 密碼:java

1988ming)mysql

一、安裝JDKlinux

下載 jdk-7-linux-i586.rpmweb

http://java.sun.com/javase/downloads/index.jspsql

# rpm –ivh jdk-7-linux-i586.rpm  
 
# vi ~/.bash_profile 
JAVA_HOME=/usr/java/jdk1.7.0 
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib 
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin 
export PATH CLASSPATH JAVA_HOME 數據庫

使環境變量馬上生效apache

# source ~/.bash_profile
# source /etc/profile瀏覽器

# java -version (jdk的版本爲jdk1.4.2則表示jdk已成功安裝)。 

二、安裝Tomcat 

下載apache-tomcat-6.0.10.tar.gz 

http://jakarta.apache.org/tomcat

# tar zxf apache-tomcat-6.0.10.tar.gz -C /usr/src
# mv /usr/src/apache-tomcat-6.0.10   /usr/src/tomcat 

# /usr/src/tomcat/bin/startup.sh           (啓動tomcat) 
                或
# /usr/src/tomcat/bin/catalina.sh start

Using CATALINA_BASE: /usr/local/tomcat 
Using CATALINA_HOME: /usr/local/tomcat 
Using CATALINA_TEMDIR: /usr/local/tomcat/temp 
Using JAVA_HOME: /usr/java/jdk1.6.0_01 

# /usr/src/tomcat/bin/catalina.sh start/stop  (啓動/關閉tomcat)

到此tomcat已經安裝完成,如今使用瀏覽器訪問 http://localhost:8080,出現tomcat默認頁面,
4) 拷貝mysql驅動
cp ./mysql-connector-java-3.1.14/mysql-connector-java-3.1.14-bin.jar

/usr/src/tomcat/webapps/ROOT/WEB-INF/lib/

3 配置JDK環境變量
修改/etc/profile,加入以下幾行
JAVA_HOME=/usr/local/jdk1.7.0
JRE=/usr/local/jdk1.7.0/jre
CLASSPATH=$JAVA_HOME/lib:$JRE/lib:/usr/src/tomcat/webapps/ROOT/WEB-INF/lib/mysql-connector-java-

3.1.14-bin.jar:.
PATH=$PATH:$JAVA_HOME/bin:$JRE/bin:.

export JAVA_HOME JRE CLASSPATH
export PATH

4 啓動TOMCAT
/usr/src/tomcat/bin/startup.sh

5 關閉TOMCAT
/usr/src/tomcat/bin/shutdown.sh

安裝mysql

# useradd -M -s /sbin/nologin  mysql
# tar zxf mysql-5.0.56.tar.gz -C /usr/src
# cd /usr/src/mysql-5.0.56
# ./configure --prefix=/usr/local/mysql
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# /usr/local/mysql/bin/mysql_install_db --user=mysql
# chown -R root.mysql /usr/local/mysql/
# chown -R mysql /usr/local/mysql/var
# echo "/usr/local/mysql/lib/mysql"  >> /etc/ld.so.conf
# ldconfig
# /usr/local/mysql/bin/mysqld_safe  --user=mysql &
# 回車(Enter鍵)
# netstat -ntpl | grep 3306
# cp support-files/mysql.server  /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 35 mysqld on
# export PATH=$PATH:/usr/local/mysql/bin
# echo "PATH=$PATH:/usr/local/mysql/bin"   >>  /etc/profile
# mysqladmin -u root password "123456"
# mysql -u root -p

> create database phpbb;
> use phpbb;
> create table phpbb(user_name char(30) not null,user_passwd char(20) not null);
> insert into phpbb.phpbb(user_name,user_passwd) values('phpbb',encrypt('123456');

6 寫mysql.jsp 測試 (先在mysql數據庫裏建個數據庫phpbb,表phpbb,用戶phpbb,密碼phpbb)
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/phpbb?

user=phpbb&password=phpbb&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="show tables";
ResultSet rs=stmt.executeQuery(sql);%>
<%while(rs.next()) {%>
<%=rs.getString(1)%>
<br>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
7 外部測試地址http://210.51.1.148:8080/jsp/mysql.jsp

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息