update.jsp

来自「jsp连接样例!详细说明了jsp的连接方法!新手值得一看!」· JSP 代码 · 共 57 行

JSP
57
字号
<%@page contentType="text/html; charset=gb2312" language = "java"%>
<%@page import = "java.sql.*"%>
<%!
String strSql;
Connection conn;
Statement stmt;
ResultSet result;
%>
<%
String id = request.getParameter("id");
try{
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	conn = DriverManager.getConnection("jdbc:odbc:quchch","sa","");
	stmt = conn.createStatement();
	strSql = "Select * From tab where id = " + id;
	result = stmt.executeQuery(strSql);
	int rsID = 0;
	String rsName = "";
	String rsContent = "";
	if(result.next()){
		rsID = result.getInt("ID");
		rsName = result.getString("Name");
		rsContent = result.getString("Content");
	}
	result.close();
	stmt.close();
	conn.close();	
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head><title>INSERT</title></head>
<body>
<table width=300>
<form action=post.jsp?opt=update method=post>
<input type=hidden name=id value=<%=rsID%>>
<tr>
<td>Name</td><td><input type=text name=rsName value=<%=rsName%>></td>
</tr>
<tr>
<td>Content</td><td><textarea name=rsContent cols=50 rows=5><%=rsContent%></textarea></td>
</tr>
<tr>
<td colspan=2 align=right><input type=submit name=sub value="修改"></td>
</tr>
</form>
</table>
</body>
</html>
<%
}catch(Exception e){
	out.println(e);
}finally{
	if(conn!=null){
       conn.close();
	}
}
%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?