修改页面需要修改的信息显示成功,但更改后并没有更新到数据库!!
修改页面的JSP代码如下
<%
String kcbh=request.getParameter("kcbh");
ResultSet rs2=cxjg.get_cxjg2(kcbh);
if(rs2.next())
{
%>
<body>
<form id="form1" method="post" action="/JWXK/servlet/EDITKC">
<table id=table1>
<tr>
<td>
<font size=2>课程编号:</font>
<input id="t1" name="t1" type="text" width=120 value="<%out.print(rs2.getString(1));%>">
</td>
<td>
<font size=2>课程名称:</font>
<input id="t2" name="t2" type="text" width=120 value="<%out.print(rs2.getString(2));%>">
</td>
</tr>
<tr>
<td>
<font size=2>学时:</font>
<input id="t3" name="t3" type="text" width=120 value="<%out.print(rs2.getString(3));%>">
</td>
<td>
<font size=2>任课教师:</font>
<input id="t4" name="t4" type="text" width=120 value="<%out.print(rs2.getString(4));%>">
</td>
</tr>
<tr>
<td>
<font size=2>上课时间:</font>
<input id="t5" name="t5" type="text" width=120 value="<%out.print(rs2.getString(7));%>">
</td>
<td>
<font size=2>上课地点:</font>
<input id="t6" name="t6" type="text" width=120 value="<%out.print(rs2.getString(8));%>">
</td>
</tr>
<tr>
<td>
<font size=2>限报人数:</font>
<input id="t7" name="t7" type="text" width=120 value="<%out.print(rs2.getString(5));%>">
</td>
<td>
<font size=2>限报院系:</font>
<input id="t9" name="t9" type="text" width=120 value="<%out.print(rs2.getString(11));%>">
</td>
</tr>
<tr>
<td>
<font size=2>限报专业:</font>
<input id="t8" name="t8" type="text" width=120 value="<%out.print(rs2.getString(10));%>">
</td>
<td>
<font size="2">限报性别:</font>
<select name="s1" id="s1" width="120">
<option value="<%out.print(rs2.getString(9));%>"><%out.print(rs2.getString(9));%></option>
<option value="无">无</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td cospan=2>
<input type="submit" value="提交">
<input type="button" value="关闭" onclick="window.close()">
</td>
</tr>
</table>
</form>
</body>
<%
}
%>
修改数据的JAVA代码如下:
Connection conn=null;
//Statement stmt=null;try
{
conn=DBConnection.getConnection();
request.setCharacterEncoding("gb2312");
String t1=request.getParameter("t1");
String t2=request.getParameter("t2");
String t3=request.getParameter("t3");
String t4=request.getParameter("t4");
String t5=request.getParameter("t5");
String t6=request.getParameter("t6");
String t7=request.getParameter("t7");
String t8=request.getParameter("t8");
String t9=request.getParameter("t9");
String s1=request.getParameter("s1");
conn=DBConnection.getConnection_access();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="update 课程表 set 课程名称='"+t2+"',学时='"+t3+"',任课教师='"+t4+"',限报人数='"+t5+"',上课时间='"+t6+"',上课地点='"+t7+"',限报性别='"+s1+"',限报专业'"+t8+"',限报院系='"+t9+"' where 课程编号='"+t1+"'";
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
System.out.print("<script>window.close();</script>");
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} public void init() throws ServletException {
}}
修改页面的JSP代码如下
<%
String kcbh=request.getParameter("kcbh");
ResultSet rs2=cxjg.get_cxjg2(kcbh);
if(rs2.next())
{
%>
<body>
<form id="form1" method="post" action="/JWXK/servlet/EDITKC">
<table id=table1>
<tr>
<td>
<font size=2>课程编号:</font>
<input id="t1" name="t1" type="text" width=120 value="<%out.print(rs2.getString(1));%>">
</td>
<td>
<font size=2>课程名称:</font>
<input id="t2" name="t2" type="text" width=120 value="<%out.print(rs2.getString(2));%>">
</td>
</tr>
<tr>
<td>
<font size=2>学时:</font>
<input id="t3" name="t3" type="text" width=120 value="<%out.print(rs2.getString(3));%>">
</td>
<td>
<font size=2>任课教师:</font>
<input id="t4" name="t4" type="text" width=120 value="<%out.print(rs2.getString(4));%>">
</td>
</tr>
<tr>
<td>
<font size=2>上课时间:</font>
<input id="t5" name="t5" type="text" width=120 value="<%out.print(rs2.getString(7));%>">
</td>
<td>
<font size=2>上课地点:</font>
<input id="t6" name="t6" type="text" width=120 value="<%out.print(rs2.getString(8));%>">
</td>
</tr>
<tr>
<td>
<font size=2>限报人数:</font>
<input id="t7" name="t7" type="text" width=120 value="<%out.print(rs2.getString(5));%>">
</td>
<td>
<font size=2>限报院系:</font>
<input id="t9" name="t9" type="text" width=120 value="<%out.print(rs2.getString(11));%>">
</td>
</tr>
<tr>
<td>
<font size=2>限报专业:</font>
<input id="t8" name="t8" type="text" width=120 value="<%out.print(rs2.getString(10));%>">
</td>
<td>
<font size="2">限报性别:</font>
<select name="s1" id="s1" width="120">
<option value="<%out.print(rs2.getString(9));%>"><%out.print(rs2.getString(9));%></option>
<option value="无">无</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td cospan=2>
<input type="submit" value="提交">
<input type="button" value="关闭" onclick="window.close()">
</td>
</tr>
</table>
</form>
</body>
<%
}
%>
修改数据的JAVA代码如下:
Connection conn=null;
//Statement stmt=null;try
{
conn=DBConnection.getConnection();
request.setCharacterEncoding("gb2312");
String t1=request.getParameter("t1");
String t2=request.getParameter("t2");
String t3=request.getParameter("t3");
String t4=request.getParameter("t4");
String t5=request.getParameter("t5");
String t6=request.getParameter("t6");
String t7=request.getParameter("t7");
String t8=request.getParameter("t8");
String t9=request.getParameter("t9");
String s1=request.getParameter("s1");
conn=DBConnection.getConnection_access();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="update 课程表 set 课程名称='"+t2+"',学时='"+t3+"',任课教师='"+t4+"',限报人数='"+t5+"',上课时间='"+t6+"',上课地点='"+t7+"',限报性别='"+s1+"',限报专业'"+t8+"',限报院系='"+t9+"' where 课程编号='"+t1+"'";
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
System.out.print("<script>window.close();</script>");
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} public void init() throws ServletException {
}}
解决方案 »
- hibernate的merge方法
- 请教:JAVA利用apache提供的包启动tomcat https服务时,Invalid Server SSL Protocol
- 一些简单问题
- 关于往Oracle数据库中插入Clob类型数据问题!如何将String类型数据转换成Clob类型?
- TOMCAT 配置!!!!!
- jsp+mysql的插入问题
- 100分求答案!关于html中的图片位置的调整问题
- Tomcat虚拟目录突然不能创建(以前都正常,Bean、Servlet、JDBC都运行过)、重装都不行
- java连接Access数据库 jdbc 驱动包 50次报错
- 如何将JB9中的Strust1.0换成Strust1.1?
- JSF页面的跳转问题
- 求高人指点诡异的java代码,包证很多人没见过。90%没用过
其他的没看出来
帮你顶下
是接受t1,t2,t3.....吗?
你把sql打印后台看一下update语句, 是否正确
System.out.print("<script>window.close();</script>"); 改成
System.out.print("sql"); 把显示出来的sql语句直接在数据库运行看看, 是否正常.
System.out.print("<script>window.close();</script>"); 这个部分你确定执行完修改操作之后页面会被关闭掉吗?
没有显示我用的是ACCESS数据库
你最好把SQL语句打印出来.
看看SQL对不对. 如果SQL没问题确保stmt.executeUpdate(sql);语句要执行成功. 在catch哪一块多写一些输出的代码看看..
还有system.out.println是输出到控制台的.
这样他只会把javascript脚本输出到控制台, 浏览器是没什么任何反应的.
你要输出到浏览器需要用writer.
PrintWriter out = response.getWriter();
out.println("你的js内容") 才可以.