用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

Essence    -  云代码空间

—— 起弦风雅,弹落繁华

Java web 的增删改查

2015-06-08|3328阅||

摘要:<%@ page language="java" contentType="text/html; charset=gb2312"     pageEncoding="gb2312"%>     <%@ page import="java.sql.*" %>

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
    <%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>学生管理</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1/JJUDB?"
     +"&useUnicode=true&characterEncoding=GB2312";
String user="root";
String pass="110806";
Connection conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
String sql= "select * from Student";
ResultSet rs = stmt.executeQuery(sql);
%>
<table border="1">
<tr>
<th>id</th>
<th>学号</th>
<th>姓名</th>
<th>班级</th>
</tr>
<% while(rs.next()){ %>
<tr>
<td><%=rs.getInt("id") %></td>
<td><%=rs.getString("studentNo") %></td>
<td><%=rs.getString("studentName") %></td>
<td><%=rs.getInt("gradeId") %></td>
</tr>
<% }
rs.close();
stmt.close();
conn.close(); %>
</table>
<a href="studentAdd.jsp">添加学生信息</a>
</body>
</html>








<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>学生管理</title>
</head>
<body> 
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1/JJUDB?"
     +"&useUnicode=true&characterEncoding=GB2312";
String user="root";
String pass="110806";
Connection conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
String sql= "select * from Grade order by id";
ResultSet rs = stmt.executeQuery(sql);
%>
   <form action="studentAddAction.jsp" method="post">
   <label>学号</label> <input type="text" name="studentNo"> <br>
   <label>姓名</label><input type="text" name="studentName"> <br>
   <label>班级</label> <select name="gradeId">
   <%
   while (rs.next()){
   %>
   <option value=<%=rs.getInt("id") %>>
   <%=rs.getString("gradeName") %></option>
   <%
   }
   rs.close();
   stmt.close();
   conn.close();
   %>
   </select><br><input type="submit" value="增加">
</body>
</html>
顶 1踩 3收藏
文章评论
    发表评论

    个人资料

    • 昵称: Essence
    • 等级: 初级程序员
    • 积分: 64
    • 代码: 2 个
    • 文章: 3 篇
    • 随想: 0 条
    • 访问: 5 次
    • 关注

    人气代码

    标签

    最新提问

      站长推荐