<%
String username = request.getParameter("username");
String password = request.getParameter("password");
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Survey;integratedSecurity=true;"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
//String SQL = "update password set =password'%" + password + "%'";
String SQL = "UPDATE [USER] SET password= '" + password + "'";
stmt = con.createStatement();
stmt.execute(SQL);
stmt.executeUpdate(password);
%>
<%=password %>修改成功。
<%
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
} finally {
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
%>
String username = request.getParameter("username");
String password = request.getParameter("password");
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Survey;integratedSecurity=true;"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
//String SQL = "update password set =password'%" + password + "%'";
String SQL = "UPDATE [USER] SET password= '" + password + "'";
stmt = con.createStatement();
stmt.execute(SQL);
stmt.executeUpdate(password);
%>
<%=password %>修改成功。
<%
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
} finally {
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
%>
<table border="2" width="100%" >
<tr><td>
<td width="40%">
<form method="post" action="search.jsp">
输入要查找的姓名:<input type="text" name="username" />
<input type="submit" />
</form><form method="post" action="serch.jsp">
输入要修改的密码:<input type="text" name="password"></form>
</td>
<td>
<table>
<tr>
<td>
用户 : 密码:
</td>
</tr>
<%
if(request.getMethod()=="POST"){
String username = request.getParameter("username");
String password = request.getParameter("password");
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Survey;integratedSecurity=true;"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM [User] where username like '%" + username + "%'";
stmt = con.createStatement();
rs=stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
%>
<tr>
<!--
<td><input type="checkbox"></td>
-->
<td><%=rs.getString("username")%></td>
<td><%=rs.getString("password")%></td>
<td>
<a href="delete.jsp?username=<%=rs.getString("username")%>" >删除用户</a>
<a href="modify.jsp?password=<%=rs.getString("password")%>" >修改密码</a>
</tr>
<%
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
%>
LZ 是新手伐
jsp中写java代码
//String SQL = "update password set =password'%" + password + "%'";
String SQL = "UPDATE [USER] SET password= '" + password + "'";SQL 语法中,update 后面跟表名且不要加“[]"
如果你的密码是存在名为user的表中,上面这句应该写为
String SQL = "UPDATE USER SET password= '" + password + "'";