Topic: 插入数据功能不能执行

  Print this page

1.插入数据功能不能执行 Copy to clipboard
Posted by: blackhorse_zou
Posted on: 2006-05-09 16:14

我用servlet写了一个对数据进行插入的程序,但是运行到stm.execute(insertString); 时就不动了,请问哪位知道我这段代码不能运行的原因,谢谢!具体情况如下:
部分代码:
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=gb2312");
PrintWriter printwriter = httpservletresponse.getWriter();
String name = httpservletrequest.getParameter("newname");
String pass1 = httpservletrequest.getParameter("newpass1");
String pass2 = httpservletrequest.getParameter("newpass2");
String uname = httpservletrequest.getParameter("username");
String ujob = httpservletrequest.getParameter("userjob");
String udep = httpservletrequest.getParameter("userdep");
if(!pass1.trim().equals(pass2.trim())){
printwriter.println("<HTML><HEAD><TITLE> 用户注册</TITLE></HEAD>");
printwriter.println("<body ><a href=\"http://192.168.0.66/website/changqing/newclient.htm\">两次输入的密码不同,请重新注册!</a>");
printwriter.println("</body></HTML>");
   }
else{
try{              
 Class.forName("oracle.jdbc.driver.OracleDriver"); 
     String s = "jdbc:oracle:thin: @sxzd:1521:CNPCCQ";
Connection connection = DriverManager.getConnection(s, "SYSTEM", "MANAGER");
Statement stm = connection.createStatement();
printwriter.println("你的信息已经提交,准备写入数据库!");
String insertString="INSERT INTO NEWUSER(name,pass,uname,ujob,udep) VALUES("+"'"+name+"',"+"'"+pass1+"',"+"'"+uname+"',"+"'"+ujob+"',"+"'"+udep+"')";            
printwriter.println(insertString); 
       stm.execute(insertString);
   printwriter.println("你的信息已经提交!"); 
      connection.commit(); 
       stm.close(); 
       connection.close();  
       printwriter.println("<HTML><HEAD><TITLE> 用户注册</TITLE></HEAD>");               
  printwriter.println("<body >你的信息已经成功提交,请等待管理员确认后,才可以使用!");  
        printwriter.println("</body></HTML>");        }   
        catch(SQLException ee){   ee.printStackTrace();          }  
        catch(Exception ee){   ee.printStackTrace();}
}
}
运行的结果为:
你的信息已经提交,准备写入数据库! INSERT INTO NEWUSER(name,pass,uname,ujob,udep) VALUES('123','123','12','12','12')

也就是说,运行到stm.execute(insertString);时,程序就不往下继续运行了!这句语句我改为stm.executeUpdate(insertString);也不能执行!
我把 INSERT INTO NEWUSER(name,pass,uname,ujob,udep) VALUES('123','123','12','12','12'),放到PLSQL里面可以执行,得到结果。
我另外做的一个数据查询的工具可以实现从数据库查询数据,而数据插入功能就不能使用了,请高手指点!

2.Re:插入数据功能不能执行 [Re: blackhorse_zou] Copy to clipboard
Posted by: blackhorse_zou
Posted on: 2006-05-10 14:46

问题暂时解决了,我重建了一张表NEWUSER,设置owner为SYSTEM(以前是SYS),这段代码就可以运行了!根据这个,我分析主要是在oracle中建立NEWUSER这张表的时候owner设置的是SYS,而连接表的时候用的是SYSTEM身份,所以不可以写入,这种解释是否正确,期待高手的指点!

3.Re:插入数据功能不能执行 [Re: blackhorse_zou] Copy to clipboard
Posted by: why
Posted on: 2006-05-10 18:11

grant proper table access
include schema name in tablename


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923