下载jdk并安装
jsp连接mysql数据库:
安装tomcat.
下载http://dev.mysql.com/downloads/connector/j/3.1.html
设置环境变量
export JAVA_HOME=/home/shuangquan/Downloads/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/mysql-connector-java-5.0.4-bin.jar:$JAVA_HOME/lib/mysql-connector-java-5.0.4-bin-g.jar
拷贝连接器到tomcat的common\lib目录下.
jsp操控mysql
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage=""%>
如果您看到下面表格内的内容,就说明连接数据库成功!
ID |
昵称 |
E-mail |
QQ |
留言内容 |
---|
<%
Class.forName("com.mysql.jdbc.Driver").newInstance(); //org.gjt.mm.mysql.Driver
String u ="jdbc:mysql://localhost/i3s?user=root&password=";//useUnicode=true&characterEncoding=gb2312";
java.sql.Connection con = java.sql.DriverManager.getConnection(u);
java.sql.Statement statement =con.createStatement();
String sql="select * from test";
java.sql.ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {%>
<%=rs.getString(1)%> |
<%}%>
<%out.print("
数据库操作成功");%>
<%
rs.close();
statement.close();
con.close();
%>
阅读(1141) | 评论(0) | 转发(0) |