调用oracle程序 [英] calling procedures of oracle

查看:61
本文介绍了调用oracle程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在oracle 10g中创建了一个名为insert_financial_year的过程,将数据插入表财政年度。我想从java中将数据插入表财务年度。我创建了一个连接到DatabaseConnection的类我还创建了一个DatabaseConnection对象。我还创建了另一个名为ptechdatabean的类,它包含变量和方法。这些变量和方法的一些常见于其他类,并且在那里使用它们。我进一步创建了另一个名为Financial_year_procedure的类调用过程insert_financial_year将数据插入到我的表财务年度中,并使用类ptechdatabean的一些(不是全部)方法和变量。我的表中总共有13列财政年度其中只有一个主键。在创建我的程序时insert_financial_year我已经指定了所有13个列名和一个标志(如果它是I-INSERTION TAKES PLACE,如果发生D删除)和2 v ariables即errbuff&errcode(OUT参数)来显示消息。已创建连接但我无法将数据插入其中。它正在给出错误。我将发送类和过程的代码。请引导我。

******************************************* *************************************

pocedure将数据插入表。

CREATE OR REPLACE PROCEDURE PR_INSERT_FINANCIAL_YEAR(P_COMPANY_ID在数量上,

P_BRANCH_ID在数量上,

P_F_YEAR在数量上,

P_FROM_DATE点开始,

P_TO_DATE点开始,

P_STATUS在煤焦,

P_ENTERED_BY号,

P_ENTERED_DATE IN DATE ,

p_Updated_By NUMBER,

p_Update_Date在日期,

p_Ip_Address在Varchar2中,

p_Mac_Address在Varchar2中,

P_Year_close在char中,

p_Flag在Char / *,

p_Errbuff Out Varchar2,

p_Errcode Out Varchar2 * /)



IS



BEGIN

IF p_Flag ='我'那么



INSERT INTO FINANCIAL_YEAR

(COMPANY_ID,

BRANCH_ID,

F_YEAR,

FROM_DATE,

TO_DATE,

状态,

enter_by,

ENTERED_DATE,

Updated_By,

Update_Date,

Ip_Address,

Mac_Address,

year_close)

VALUES

(P_COMPANY_ID,

P_BRANCH_ID,

P_F_YEAR,

P_FROM_DATE,

P_TO_DATE,

P_STATUS,

P_ENTERED_BY,

P_ENTERED_DATE,

p_Updated_By,

p_Update_Date,

p_Ip_Address,

p_Mac_Address,

p_year_close);



p_Errbuff:='交易保存简单......' ;

p_Errcode:='001';

END IF;

commit;

END;

********************************************* ************************************************** *

//类使用程序将数据插入表中。这个lass给出了错误

包Ptech;



import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java。 sql.Types;

import java.util.Arra yList;



公共类Financial_Year_Procedure

{



public void Call_Financial_Year_Procedure( PtechDataBean PDB)抛出ClassNotFoundException的,的SQLException

{

的DatabaseConnection data_conn =新的DatabaseConnection();

连接Oracle_Connect = data_conn.Oracle_Connect(); <登记/>
的CallableStatement CS = Oracle_Connect.prepareCall( {调用PR_INSERT_FINANCIAL_YEAR(,,,,,,,,,,,,,??????????????});

cs.setInt(1,pdb.getCompany_id());

cs.setInt(2,pdb.getBranch_id());

cs.setInt(3,pdb.getf_year());

cs.setString(4,pdb.getFrom_Date());

cs.setString(5,pdb。 getTo_Date());

cs.setString(6,pdb.getStatus());

cs.setInt(7,pdb.getEntered_By());

cs.setString(8,pdb.getEntered_Date());

cs.setInt(9,pdb.getUpdated_By() );

cs.setString(10,pdb.getUpdate_Date());

cs.setString(11,pdb.getIp_Address());

cs.setString(12,pdb.getMac_Address());

cs.setString(13,pdb.getYear_close());

cs.setString(14, pdb.getFlag());

cs.registerOutParameter(15,Types.VARCHAR);

cs.registerOutParameter(16,Types.VARCHAR);

cs.executeUpdate();

ArrayList al = new ArrayList();

{

al.add(cs.getString( 15));

al.add(cs.getString(16));

}

返回al;

$



public static void main(String args [])抛出ClassNotFoundException,SQLException {

Financial_Year_Procedure fy = new Financial_Year_Procedure();

PtechDataBean pdb = new PtechDataBean();

pdb.setCompany_id(13);

pdb.setBranch_id(14);

pdb.setf_year(2011);

pdb.setFrom_Date();

pdb.setTO_Date( );

pdb.setStatus(E);

pdb.setEntered_By(1);

pdb.setEntered_Date( );

pdb.setUpdated_By(1);

pdb.setUpdate_Date();

pdb.setIp_Address();

pdb.setMac_Address();

pdb.setYear_close(N);

pdb.setFlag(I);

pdb.setErrbuff();

pdb.setErrcode();

ArrayList al = fy.Call_Financial_Year_Procedure(pdb);

fy.Call_Financial_Year_Procedure(pdb);

System.out.println(al);



}

}

*********************************** ***************************************

I have created a procedure named "insert_financial_year" in oracle 10g to insert data into table "financial year".I want to insert data into table "financial year" from java.I have created a class "DatabaseConnection" that connects to database.I have also created object of "DatabaseConnection".I also have created another class called "ptechdatabean" that contains variables and methods.Some of this variables and methods are common to other classes and they are used there.Further I have created another class called "Financial_year_procedure" that calls the procedure "insert_financial_year" to insert data into my table "financial year" and also uses some(not all) methods and variables of class "ptechdatabean".There are a total of 13 columns in my table "financial year" out of which there is a single primary key.While creating my procedure "insert_financial_year" I have specified all 13 column names along with a flag("if it is I-INSERTION TAKES PLACE,if D-deletion takes place") and 2 variables namely "errbuff & errcode(OUT parameters)" to display messages.Connection has been created but i am not able to insert data into it.It is giving errors.I will send the code of classes and procedure.kindly guide me.
********************************************************************************
pocedure to insert data into table.
CREATE OR REPLACE PROCEDURE PR_INSERT_FINANCIAL_YEAR(P_COMPANY_ID IN NUMBER,
P_BRANCH_ID IN NUMBER,
P_F_YEAR IN NUMBER,
P_FROM_DATE IN DATE,
P_TO_DATE IN DATE,
P_STATUS IN CHAR,
P_ENTERED_BY NUMBER,
P_ENTERED_DATE IN DATE,
p_Updated_By NUMBER,
p_Update_Date In Date,
p_Ip_Address In Varchar2,
p_Mac_Address In Varchar2,
P_Year_close in char,
p_Flag In Char/*,
p_Errbuff Out Varchar2,
p_Errcode Out Varchar2*/)

IS

BEGIN
IF p_Flag = 'I' THEN

INSERT INTO FINANCIAL_YEAR
(COMPANY_ID,
BRANCH_ID,
F_YEAR,
FROM_DATE,
TO_DATE,
STATUS,
entered_by,
ENTERED_DATE,
Updated_By,
Update_Date,
Ip_Address,
Mac_Address,
year_close)
VALUES
(P_COMPANY_ID,
P_BRANCH_ID,
P_F_YEAR,
P_FROM_DATE,
P_TO_DATE,
P_STATUS,
P_ENTERED_BY,
P_ENTERED_DATE,
p_Updated_By,
p_Update_Date,
p_Ip_Address,
p_Mac_Address,
p_year_close);

p_Errbuff := 'Transaction Saved succssfully..';
p_Errcode := '001';
END IF;
commit;
END;
************************************************************************************************
//class using procedure to insert data into table.This lass is giving errors
package Ptech;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;

public class Financial_Year_Procedure
{

public void Call_Financial_Year_Procedure(PtechDataBean pdb) throws ClassNotFoundException, SQLException
{
DatabaseConnection data_conn = new DatabaseConnection();
Connection Oracle_Connect = data_conn.Oracle_Connect();
CallableStatement cs = Oracle_Connect.prepareCall("{call PR_INSERT_FINANCIAL_YEAR(?,?,?,?,?,?,?,?,?,?,?,?,?,?}");
cs.setInt(1, pdb.getCompany_id());
cs.setInt(2, pdb.getBranch_id());
cs.setInt(3, pdb.getf_year());
cs.setString(4, pdb.getFrom_Date());
cs.setString(5, pdb.getTo_Date());
cs.setString(6, pdb.getStatus());
cs.setInt(7, pdb.getEntered_By());
cs.setString(8, pdb.getEntered_Date());
cs.setInt(9, pdb.getUpdated_By());
cs.setString(10, pdb.getUpdate_Date());
cs.setString(11, pdb.getIp_Address());
cs.setString(12, pdb.getMac_Address());
cs.setString(13, pdb.getYear_close());
cs.setString(14, pdb.getFlag());
cs.registerOutParameter(15, Types.VARCHAR);
cs.registerOutParameter(16, Types.VARCHAR);
cs.executeUpdate();
ArrayList al = new ArrayList();
{
al.add(cs.getString(15));
al.add(cs.getString(16));
}
return al;
}

public static void main(String args[]) throws ClassNotFoundException, SQLException {
Financial_Year_Procedure fy = new Financial_Year_Procedure();
PtechDataBean pdb = new PtechDataBean();
pdb.setCompany_id(13);
pdb.setBranch_id(14);
pdb.setf_year(2011);
pdb.setFrom_Date(" ");
pdb.setTO_Date(" ");
pdb.setStatus("E");
pdb.setEntered_By(1);
pdb.setEntered_Date(" ");
pdb.setUpdated_By(1);
pdb.setUpdate_Date(" ");
pdb.setIp_Address(" ");
pdb.setMac_Address(" ");
pdb.setYear_close("N");
pdb.setFlag("I");
pdb.setErrbuff(" ");
pdb.setErrcode(" ");
ArrayList al = fy.Call_Financial_Year_Procedure(pdb);
fy.Call_Financial_Year_Procedure(pdb);
System.out.println(al);

}
}
**************************************************************************

推荐答案

你的政治家有语法问题t。

更改

You've got syntax problems in your statement.
Change
CallableStatement cs = Oracle_Connect.prepareCall("{call PR_INSERT_FINANCIAL_YEAR(?,?,?,?,?,?,?,?,?,?,?,?,?,?}");



to


to

CallableStatement cs = Oracle_Connect.prepareCall("{call PR_INSERT_FINANCIAL_YEAR(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");





你错过了最后的括号。



希望这有帮助,

Fredrik



You're missing the last parentheses.

Hope this helps,
Fredrik


这篇关于调用oracle程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆