首页编程preparecall(preparedStatement.executeUpdate() 无法执行)

preparecall(preparedStatement.executeUpdate() 无法执行)

编程之家2023-11-02102次浏览

大家好,今天给各位分享preparecall的一些知识,其中也会对preparedStatement.executeUpdate() 无法执行进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!

preparecall(preparedStatement.executeUpdate() 无法执行)

oracle存储过程的基本语法及注意事项

基本结构

CREATE OR REPLACE PROCEDURE存储过程名字

(

参数 IN NUMBER

参数 IN NUMBER

preparecall(preparedStatement.executeUpdate() 无法执行)

) IS

变量 INTEGER:=;

变量 DATE;

BEGIN

END存储过程名字

SELECT INTO STATEMENT

preparecall(preparedStatement.executeUpdate() 无法执行)

将select查询的结果存入到变量中可以同时将多个列存储多个变量中必须有一条

记录否则抛出异常(如果没有记录抛出NO_DATA_FOUND)

例子

BEGIN

SELECT col col into变量变量 FROM typestruct where xxx;

EXCEPTION

WHEN NO_DATA_FOUND THEN

xxxx;

END;

IF判断

IF V_TEST= THEN

BEGIN

do something

END;

END IF;

while循环

WHILE V_TEST= LOOP

BEGIN

XXXX

END;

END LOOP;

变量赋值

V_TEST:=;

用for in使用cursor

IS

CURSOR cur IS SELECT* FROM xxx;

BEGIN

FOR cur_result in cur LOOP

BEGIN

V_SUM:=cur_result列名+cur_result列名

END;

END LOOP;

END;

带参数的cursor

CURSOR C_USER(C_ID NUMBER) IS SELECT NAME FROM USER WHERE TYPEID=C_ID;

OPEN C_USER(变量值);

LOOP

FETCH C_USER INTO V_NAME;

EXIT FETCH C_USER%NOTFOUND;

do something

END LOOP;

CLOSE C_USER;

用pl/sql developer debug

连接数据库后建立一个Test WINDOW

在窗口输入调用SP的代码 F开始debug CTRL+N单步调试

关于oracle存储过程的若干问题备忘

在oracle中数据表别名不能加as如

select a appname from appinfo a;正确

select a appname from appinfo as a;错误

也许是怕和oracle中的存储过程中的关键字as冲突的问题吧

在存储过程中 select某一字段时后面必须紧跟into如果select整个记录利用游标的话就另当别论了

select af keynode into kn from APPFOUNDATION af where af appid=aid and af foundationid=fid;有into正确编译

select af keynode from APPFOUNDATION af where af appid=aid and af foundationid=fid;没有into编译报错提示 Compilation

Error: PLS: an INTO clause is expected in this SELECT statement

在利用select into语法时必须先确保数据库中有该条记录否则会报出 no data found异常

可以在该语法之前先利用select count(*) from查看数据库中是否存在该记录如果存在再利用select into

在存储过程中别名不能和字段名称相同否则虽然编译可以通过但在运行阶段会报错

select keynode into kn from APPFOUNDATION where appid=aid and foundationid=fid;正确运行

select af keynode into kn from APPFOUNDATION af where af appid=appid and af foundationid=foundationid;运行阶段报错提示

ORA:exact fetch returns more than requested number of rows

在存储过程中关于出现null的问题

假设有一个表A定义如下

create table A(

id varchar() primary key not null

vcount number() not null

bid varchar() not null外键

);

如果在存储过程中使用如下语句

select sum(vcount) into fcount from A where bid= xxxxxx;

如果A表中不存在bid= xxxxxx的记录则fcount=null(即使fcount定义时设置了默认值如 fcount number():=依然无效 fcount还是会变成null)这样以后使用fcount时就可能有问题所以在这里最好先判断一下

if fcount is null then

fcount:=;

end if;

这样就一切ok了

Hibernate调用oracle存储过程

this pnumberManager getHibernateTemplate() execute(

new HibernateCallback(){

public Object doInHibernate(Session session)

throws HibernateException SQLException{

CallableStatement cs= session

nnection()

prepareCall({call modifyapppnumber_remain(?)});

cs setString( foundationid);

cs execute();

return null;

}

lishixinzhi/Article/program/Oracle/201311/16725

preparedstatement executeupdate 可以执行存储过程么

CallableStatement stmt=connection.prepareCall("{ call用于更新的存储过程名称(?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.executeUpdate();

CallableStatement stmt=connection.prepareCall("{ call用于查询过程名称(?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.executeQuery();

如果你需要传回参数,你可以这样:

CallableStatement stmt=connection.prepareCall("{ call用于查询过程名称(?,?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.registerOutParameter(1,自己定义类型);

stmt.executeQuery();

自己定义类型 x=stmt.get自己定义类型(1);//获得传回的参数值,参数类型要自己定义的。

以下是官方文档上的原话:

public interface CallableStatementextends PreparedStatement用于执行 SQL存储过程的接口。JDBC API提供了一个存储过程 SQL转义语法,该语法允许对所有 RDBMS使用标准方式调用存储过程。此转义语法有一个包含结果参数的形式和一个不包含结果参数的形式。如果使用结果参数,则必须将其注册为 OUT型参数。其他参数可用于输入、输出或同时用于二者。参数是根据编号按顺序引用的,第一个参数的编号是 1。

{?= call<procedure-name>[<arg1>,<arg2>,...]}

{call<procedure-name>[<arg1>,<arg2>,...]}

preparedStatement.executeUpdate() 无法执行

CallableStatement stmt=connection.prepareCall("{ call用于更新的存储过程名称(?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.executeUpdate();

CallableStatement stmt=connection.prepareCall("{ call用于查询过程名称(?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.executeQuery();

如果你需要传回参数,你可以这样:

CallableStatement stmt=connection.prepareCall("{ call用于查询过程名称(?,?,?,?)}");

stmt.setString(1,"字符");

stmt.setDate(2,Date);

stmt.setDate(3,Date);

stmt.registerOutParameter(1,自己定义类型);

stmt.executeQuery();

自己定义类型 x=stmt.get自己定义类型(1);//获得传回的参数值,参数类型要自己定义的。

以下是官方文档上的原话:

public interface CallableStatementextends PreparedStatement用于执行 SQL存储过程的接口。JDBC API提供了一个存储过程 SQL转义语法,该语法允许对所有 RDBMS使用标准方式调用存储过程。此转义语法有一个包含结果参数的形式和一个不包含结果参数的形式。如果使用结果参数,则必须将其注册为 OUT型参数。其他参数可用于输入、输出或同时用于二者。参数是根据编号按顺序引用的,第一个参数的编号是 1。

{?= call<procedure-name>[<arg1>,<arg2>,...]}

{call<procedure-name>[<arg1>,<arg2>,...]}

OK,关于preparecall和preparedStatement.executeUpdate() 无法执行的内容到此结束了,希望对大家有所帮助。

java教程下载 JAVA从入门到精通视频教程哪里有下载baidu 百度,百度可以干什么