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

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>");
}
可是执行了存储过程后,数据并没有进入数据库
...全文
39 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);
如果存储过程没有写错的话,应该就没问题了。
不需要开发,0行代码写接口服务,sql编程,只要会sql就会写接口服务,让后端变得更简单,简单4步短短5分钟,立马上手,java小白也可以写接口。订阅课程后可以免费获取发布版进行使用和测试。 0行代码写服务的需要来源案例一,当时有个项目,有400张表,都是管理系统,单表维护的内容较多,当时的项目团队是13人,前后端都写,那时候还没有springboot,用的是ssm,mybatis刚出来,有了替代hibernate的趋势,ifelse写了一堆又一堆,实体类也是,当时的后端分了7层☒,天天加班干这活,复制粘贴,很容易犯错,实体类多人引用修改,真的是废了很大的劲……案例二,也是一个比较大的项目,两千万多万那种,当时为了拿项目,需要快速实现原型给客户看,要求比较高,虽说是原型但是数据全部需要实时,这时候就需要大量编写数据接口,同样编写接口这件事难度倒是不大,但是量大,编写过程手写很容易出错……案例三,以前管理的团队主要做移动端开发,里面的项目会涉及到推送,管理系统,数据采集与同步,总之很多内容,需要前后端通吃,我不仅需要出方案,设计原型,设计数据库,出报价,沟通需求,还要写后端框架,数据接口与数据采集,开发前端(web端),移动端,管理所有项目,但是那时候招的人只会写移动端,实在是忙不过来,我就想能不能有个框架让不会写java的人能写接口,因为写移动端sqlite总是会用的,也就是说写sql不是难点……基于以上三点需求的积累,我利用业余时间写了一个后端框架,完成了这样的需求,刚开始是需要写三行代码完成一个接口,经过后面优化,现在不写代码也可以实现……  本框架涉及的知识点比较多,目前提供最基础版供大家学习和使用,后期逐步推出框架具体的教程和功能内容,下期我们讲如何在实际项目中通过部署版如何完成所需要的接口编写,欢迎大家订阅。

81,092

社区成员

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

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