当前位置: 代码迷 >> J2EE >> 更新话语错了么
  详细解决方案

更新话语错了么

热度:23   发布时间:2016-04-22 01:02:27.0
更新语句错了么?
JDBC实现数据库数据修改

可以执行,可是执行了该行的列值没有改变,也不报错

请问是不是更新语句错哪了?

<%
request.setCharacterEncoding("GB18030");

String s = request.getParameter("id");
String twm = request.getParameter("t5");
String wz = request.getParameter("t6");

if(twm !=""&& wz!="" ){
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/justshow?user=root&password=123");
Statement stmt = conn.createStatement();
 
stmt.executeUpdate("update xueyi set weizhi='"+twm+"',jiawei='"+wz+"'where tanwei='"+s+"'");
 

stmt.close();
conn.close();

response.sendRedirect("zhu.jsp");

}else{
response.sendRedirect("xue12.jsp");
}

%>

------解决方案--------------------
你把这段代码改成这样 如下
Java code
Connection conn = null;Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection("jdbc:mysql://localhost/justshow?user=root&password=123");Statement stmt = conn.createStatement();  stmt.executeUpdate("update xueyi set weizhi='"+twm+"',jiawei='"+wz+"'where tanwei='"+s+"'");  stmt.close();conn.close();
------解决方案--------------------
探讨

你把这段代码改成这样 如下
Java code
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/justshow?user=root&amp;password=123");
Statement s……

------解决方案--------------------
LS貌似只加了 try{}catch{} 有用吗?

LZ 还是调试下吧,既然执行了也不报错,单步走走看~~~
------解决方案--------------------
stmt.executeUpdate("update xueyi set weizhi='"+twm+"',jiawei='"+wz+"'where tanwei='"+s+"'");

这地方的符号好像是中文的吧 8319449高级JAVA群
------解决方案--------------------
是不是需要commit()一下,不太清楚
------解决方案--------------------
事务没有开启,加上试试。
------解决方案--------------------
SQL语句有问题吧

"update xueyi set weizhi='"+twm+"',jiawei='"+wz+"'where tanwei='"+s+"'"
where处要个空格
------解决方案--------------------

conn = DriverManager.getConnection("jdbc:mysql://localhost/justshow?user=root&password=123"); 这应该是sqlserver的方式

conn = DriverManager.getConnection("jdbcjdbc:mysql://127.0.0.1:3306/db","username","password"); //我记得好像是这样写的
  相关解决方案