mysql 增删改查
<%@ page contentType="text/html" language="java" pageEncoding="GBK" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>insert Test</title>
</head>
<body>
<h2>will it happen</h2>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(Exception e){
out.print(e.toString());
}
try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/db?" +
"user=root&password=pf");
Statement stmt = conn.createStatement();
/* //插入
stmt.executeUpdate("insert into bg(username,userPwd)values('zhous','xiao')");
*/
/*
//删除
stmt.executeUpdate("delete from bg where id = 7");
*/
/*
//修改
stmt.executeUpdate("update bg set userName = 'haveyouchange' where id = 6");
*/
/*
//查询
ResultSet rs = stmt.executeQuery("select userName,userPwd from bg");
while(rs.next()){
out.println("用户名:" + rs.getString("userName") + "密码:" + rs.getString("userPwd") + "<hr />");
}
*/
}catch(SQLException e){
out.println(e);
}
%>
</body>
</html>