<%--
Document : Updatemysql
Created on : 2016-6-4, 10:01:31
Author : zhanghuiqing
--%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
Connection con;
Statement st;
ResultSet rs;
%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mytest","root","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from course");
}
catch(Exception e){
e.printStackTrace();
}
%>
<br>
<table border="1" bordercolor="#FF0000" bgcolor="#EFEFEF" width="400">
<tr bgcolor="CCCCCC" align="center">
<td>课程号</td>
<td>课程名</td>
<td>教师号</td>
</tr>
<tr align="center">
<td><%=rs.getInt("cno")%></td>
<td><%=rs.getString("cname")%></td>
<td><%=rs.getInt("tno")%></td>
</tr>
</table>
<%
try{
int count=st.executeUpdate("Update course set cname='Servlet' where cno='1017'");
if(count!=0){
System.out.print("影响行数"+count);
rs=st.executeQuery("select * from course");
}
}
catch(Exception e){
e.printStackTrace();
}
%>
<br>
更新后的记录
<br>
<table border="1" bordercolor="#FF0000" bgcolor="#EFEFEF" width="400">
<tr bgcolor="CCCCCC" align="center">
<td>课程号</td>
<td>课程名</td>
<td>教师号</td>
</tr>
<%rs.first();%>
<tr align="center">
<td><%=rs.getInt("cno")%></td>
<td><%=rs.getString("cname")%></td>
<td><%=rs.getInt("tno")%></td>
</tr>
</table>
<%
rs.close();
st.close();
con.close();
%>
</body>
</html>
_潇潇暮雨