userlist.jsp用来获取数据库中的用户信息 以表格的形式返回 点击修改时连接打到useredit.jsp<body>
<form action="" method="post">
<table border="1">
<th>编号</th><th>用户名</th><th>密码</th><th>操作</th>
<%
String sql="SELECT bh,yhm,mm FROM user";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "mysql");
Statement statement=conn.createStatement();
ResultSet rs=statement.executeQuery(sql);
while(rs.next())
{
int bh=rs.getInt(1);
String yhm=rs.getString("yhm");
String mm=rs.getString("mm");
out.print("<tr>");
out.print("<td>"+bh+"</td>");
out.print("<td>"+yhm+"</td>");
out.print("<td>"+mm+"</td>");
out.print("<td><a href='dodelete.jsp?id="+bh+"'>删除</a> <a href='useredit.jsp?id="+bh+"'>修改</a></td>");
out.print("</tr>");
System.out.print(bh);
}
conn.close();
statement.close();
rs.close();
}
catch(Exception e)
{
e.printStackTrace();}%>
</table>
</form>
</body>useredit.jsp 用来获取用户数据库中的信息<%
String sql="SELECT yhm,mm FROM user WHERE bh="+Integer.parseInt(request.getParameter("id"));
String name="";
String mm="";
String path="";
int id=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mysql");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery(sql);
System.out.print(sql);
if(rs.next())
{
name=rs.getString("yhm");
mm=rs.getString("mm");
id = rs.getInt("bh");
}
else
{
name="";
mm="";
}
path = "update.jsp?id=" + id;
c.close();
s.close();
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}%>
<form action="<%=path %>" method="post">
用户名:<input type="text" name="username" value="<%=name %>"/><br>
密码:<input type="password" name="password" value="<%=mm %>"/><br>
确认密码:<input type="password" name="qrpassword"/><br>
<input type="submit" value="提交"/>
<input type="reset" value="取消"/>
</form>
</body>update.jsp 用来执行更新
<%
String yhm=request.getParameter("yhm");
String mm=request.getParameter("mm");
String sql="UPDATE user SET yhm=?,mm=? WHERE bh="+request.getParameter("id");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mysql");
PreparedStatement ps=c.prepareStatement(sql);
ps.setString(1, yhm);
ps.setString(2, mm);
ps.executeUpdate();int result=ps.executeUpdate();System.out.println(sql);if(result==1)
{
out.print("更新成功!");
response.sendRedirect("userlist.jsp");
}
else
{
out.print("更新失败!");
}}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>在执行点击修改时就会有异常
SELECT yhm,mm FROM user WHERE bh=1java.sql.SQLException: Column 'bh' not found.
bh=1了为什么还说没找到?
艰苦啊我调了三个小时了
先跪谢了!
<form action="" method="post">
<table border="1">
<th>编号</th><th>用户名</th><th>密码</th><th>操作</th>
<%
String sql="SELECT bh,yhm,mm FROM user";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "mysql");
Statement statement=conn.createStatement();
ResultSet rs=statement.executeQuery(sql);
while(rs.next())
{
int bh=rs.getInt(1);
String yhm=rs.getString("yhm");
String mm=rs.getString("mm");
out.print("<tr>");
out.print("<td>"+bh+"</td>");
out.print("<td>"+yhm+"</td>");
out.print("<td>"+mm+"</td>");
out.print("<td><a href='dodelete.jsp?id="+bh+"'>删除</a> <a href='useredit.jsp?id="+bh+"'>修改</a></td>");
out.print("</tr>");
System.out.print(bh);
}
conn.close();
statement.close();
rs.close();
}
catch(Exception e)
{
e.printStackTrace();}%>
</table>
</form>
</body>useredit.jsp 用来获取用户数据库中的信息<%
String sql="SELECT yhm,mm FROM user WHERE bh="+Integer.parseInt(request.getParameter("id"));
String name="";
String mm="";
String path="";
int id=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mysql");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery(sql);
System.out.print(sql);
if(rs.next())
{
name=rs.getString("yhm");
mm=rs.getString("mm");
id = rs.getInt("bh");
}
else
{
name="";
mm="";
}
path = "update.jsp?id=" + id;
c.close();
s.close();
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}%>
<form action="<%=path %>" method="post">
用户名:<input type="text" name="username" value="<%=name %>"/><br>
密码:<input type="password" name="password" value="<%=mm %>"/><br>
确认密码:<input type="password" name="qrpassword"/><br>
<input type="submit" value="提交"/>
<input type="reset" value="取消"/>
</form>
</body>update.jsp 用来执行更新
<%
String yhm=request.getParameter("yhm");
String mm=request.getParameter("mm");
String sql="UPDATE user SET yhm=?,mm=? WHERE bh="+request.getParameter("id");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mysql");
PreparedStatement ps=c.prepareStatement(sql);
ps.setString(1, yhm);
ps.setString(2, mm);
ps.executeUpdate();int result=ps.executeUpdate();System.out.println(sql);if(result==1)
{
out.print("更新成功!");
response.sendRedirect("userlist.jsp");
}
else
{
out.print("更新失败!");
}}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>在执行点击修改时就会有异常
SELECT yhm,mm FROM user WHERE bh=1java.sql.SQLException: Column 'bh' not found.
bh=1了为什么还说没找到?
艰苦啊我调了三个小时了
先跪谢了!
解决方案 »
- Servlet下得不到参数
- 用C抓取网页的gzip数据、然后把这个数据放入到Memcached缓存里、再用java把数据从Memcached里取出来!(高人进)
- hibernate的setFirstResult(a),setMaxResults(b)后,不按照一定顺序取值
- 求教无限图片上传的问题!!!
- 如何判断超时问题,请各位高手指教!!!谢谢!!!
- 求助:如何用Corba客户端(java代码)访问EJB?(50分求助)
- 我是EJB初学者,请有经验的朋友帮我看一下这两个问题
- 如何在JTable中彻底删除一列??
- 这个问题闷死我了,求助于各位了,Tomcat的问题!
- 请教,在linux做j2ee,用什么版本linux比较好,红旗的怎么样??
- 观察者模式(Observer)的直观实现(小明旅游的故事)
- mybatis 连接mysql乱码
把控制台输出的sql语句放进你的sql界面去执行一下
但是点了修改后就有异常了