oracle更新表没有抛出出异常,但表中数据没有改变!求高人指点啊!!!
本帖最后由 yuanye348623610 于 2013-03-23 12:38:55 编辑
oracle更新表没有抛出出异常,但表中数据没有改变!
Java 代码:
@Test
public void testUpdateTea()
{
Connection conn = ConnectionFactory.getConnection();
String sql = "update teacher "+"set tName=?,tTel=? "+"where tid=?";
try
{
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "唐三藏");
pstmt.setString(2, "010000");
pstmt.setString(3, "2013100");
pstmt.execute();
conn.commit();
JdbcUtil.close(pstmt, conn);
} catch (SQLException e)
{
e.printStackTrace();
}
}
/* ConnectionFactory和JdbcUtil是我自己写的两个工具类,经测试没问题 */
teacher表:
CREATE TABLE "TEACHER"(
"TID" CHAR(8),
"TNAME" VARCHAR2(30) NOT NULL ENABLE,
"TSEX" CHAR(4),
"TTEL" CHAR(13),
FOREIGN KEY ("TID") REFERENCES "USERS" ("USERID") ON DELETE CASCADE ENABLE
);
通过命令提示行,连接oracle数据库后执行:update teacher set tName="唐三藏",tTel="010000" where tid="2013100"; 是没问题的,能够成功更新数据!
另外,我通过如下代码:
public Boolean updateStu(Student stu)
{
conn = ConnectionFactory.getConnection();
String sql = "update student " + " set sName =? , sAge =? "+ " where sid = ?";
try
{
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, stu.getsName());
pstmt.setString(2, stu.getsAge());
pstmt.setString(3, stu.getsId());