帮忙看看这样写有问题么?

xunxunmimi 2003-08-23 11:10:33
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
int idx=Integer.parseInt(request.getParameter("index"));//为jsp页面里的下拉列表框的值 option value
String str=request.getParameter("content");//多行文本框 textarea的值

Connection con=null;

boolean br=false;
int count;
try
{
con=WebUtil.getDbConnection(this.getServletContext(),request);
con.prepareCall("call prc_ytrb(idx,str) into br");
if(br=true)
{

out.println("<html><head>");
out.println("<title>提示</title>");
out.print("</head>");
out.println("<body>");

out.println("<p>a:<%=idx%></p>");
out.println("<p>b:<%=str%></p>");
out.println("<p>c:<%=br%></p>");

out.println("<p><div align='center'> 信息录入成功 !</div></p>");
out.println("<p><div align='center'><INPUT TYPE='button' name='back' value='返 回' onclick='history.go(-2)'</div></p>");
out.println("</body>");
out.println("</html>");
}
else
{
out.println("<html><head>");
out.println("<title>提示</title>");
out.print("</head>");
out.println("<body>");
out.println("<h1><%=idx%></h1>");
out.println("<h1><%=str%></h1>");
out.println("<h1><%=br%></h1>");
out.println("<p> </p>");
out.println("<p> </p>");
out.println("<p> </p>");
out.println("<p><div align='center'> 信息录入失败 !</div></p>");
out.println("<p><div align='center'><INPUT TYPE='button' name='back' value='返 回' onclick='history.go(-2)'</div></p>");
out.println("</body>");
out.println("</html>");
}
}
catch(Exception e)
{
e.printStackTrace() ;
}
finally
{

con=null;

}
out.println("<html>");
out.println("<head><title>InsertServlet</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("</body></html>");
}
可是执行了存储过程后,数据并没有进入数据库
...全文
34 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xunxunmimi 2003-08-23
  • 打赏
  • 举报
回复
改过了,可是为什么连try块都不执行
salx 2003-08-23
  • 打赏
  • 举报
回复
你的br没有被赋值无法看到你要的结果,按楼上的修改一切ok
liad 2003-08-23
  • 打赏
  • 举报
回复
// PLSQLExample.java
/**
* This sample shows how to call a PL/SQL stored procedure using the SQL92
* syntax. See also the other sample PLSQL.java.
*/

import java.sql.*;
import java.io.*;

class PLSQLExample
{
public static void main (String args [])
throws SQLException, IOException
{
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");

// Create a statement
Statement stmt = conn.createStatement ();

// Create the stored function
stmt.execute ("create or replace function RAISESAL (name CHAR, raise NUMBER) return NUMBER is begin return raise + 100000; end;");

// Close the statement
stmt.close();

// Prepare to call the stored procedure RAISESAL.
// This sample uses the SQL92 syntax
CallableStatement cstmt = conn.prepareCall ("{? = call RAISESAL (?, ?)}");

// Declare that the first ? is a return value of type Int
cstmt.registerOutParameter (1, Types.INTEGER);

// We want to raise LESLIE's salary by 20,000
cstmt.setString (2, "LESLIE"); // The name argument is the second ?
cstmt.setInt (3, 20000); // The raise argument is the third ?

// Do the raise
cstmt.execute ();

// Get the new salary back
int new_salary = cstmt.getInt (1);

System.out.println ("The new salary is: " + new_salary);

// Close the statement
cstmt.close();

// Close the connection
conn.close();
}
}

cui_yihao 2003-08-23
  • 打赏
  • 举报
回复
boolean br=false;
int count;
try
{
con=WebUtil.getDbConnection(this.getServletContext(),request);
// con.prepareCall("call prc_ytrb(idx,str) into br");
if....

注释部分改为:
Statement stmt = con.createStatement();
count = stmt.executeUpdate("prc_ytrb "+idx+","+str); //插入的行数
br = count > 0 ? true : false; //0行表示插入失败

salx 2003-08-23
  • 打赏
  • 举报
回复
有什么错误报么?
xunxunmimi 2003-08-23
  • 打赏
  • 举报
回复
大家不要这样哦,看一下吧
xunxunmimi 2003-08-23
  • 打赏
  • 举报
回复
up
xunxunmimi 2003-08-23
  • 打赏
  • 举报
回复
谢谢各位大侠,给看一下好么?
yangtaylor 2003-08-23
  • 打赏
  • 举报
回复
con.prepareCall("call prc_ytrb(idx,str) into br");
这句改成
String SQLclause = "call prc_ytrb("+idx+","+str+") into br";
con.prepareCall(SQLclause);
如果存储过程没有写错的话,应该就没问题了。

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧