windows下jsp+mysql网站环境配置方法第2/2页
2024-07-24 12:41:03
供稿:网友
为参考网上的资料安装jsp网站的总结.
四、JSP连接mysql测试
.建立数据库xia
打开命令行窗口,输入:
mysql -h localhost -u root -p
crate database xia;
use xia;
crate table member(id int(8) primary key,name varchar(0));
insrt into member values(,'yang');
insrt into member(name,id) values('xia',2);
(安全:为数据库设置权限(用户和密码)
命令:grant all privileges on shujuku.* to test@localhost identified by “23456”;
当你执行完这个命令以后,只要你再以用户名:test,密码:23456登录时你就只可以对shujuku这个数据库操作,
这样避开使用root,对数据库的安全有很大帮助.)
2.把以下文件保存为index.jsp到C:/Program Files/Apache Software Foundation/Tomcat 4./webapps/ROOT
----------------begin----------------------
复制代码 代码如下:
<%@ page contentType="text/html; charset=gb232" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="";
//数据库名
String dbName="xia";
//表名
String tableName="member";
//联结字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.crateStatement();
String sql="Selct * FROM "+tableName;
ResultSet rs = statement.executeQuery(sql);
//获得数据结果集合
ResultSetMetaData rmeta = rs.getMetaData();
//确定数据集的列数,亦字段数
int numColumns=rmeta.getColumnCount();
// 输出每一个数据值
out.print("id");
out.print("|");
out.print("name");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString()+" ");
out.print("|");
out.print(rs.getString(2));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
%>
--------------------end------------------------
输入http://localhost:8080测试
五、安装网站程序
)、拷贝文件
.拷贝C:/Program Files/MySQL/MySQL Server 5.0/data/dataname
2.把
C:/Program Files/Apache Software Foundation/Tomcat 4./webapps/ROOT/mywebroot
C:/Program Files/Apache Software Foundation/Tomcat 4./webapps/ROOT/web-inf
目录拷贝过去
3.建立
C:/Program Files/Apache Software Foundation/Tomcat 4./webapps/ROOT/web-inf/classes
把用到的包拷贝到
C:/Program Files/Apache Software Foundation/Tomcat 4./webapps/ROOT/web-inf/classes
目录下面
2)、javabean安装配置测试
建立自己的Bean:
.文件名TestBean.java:
--------begin---------
package test;
public class TestBean{
private String name = null;
public TestBean(String strName_p){