Executing a Stored procedure
I'm trying to execute an oracle stored procedure that has an in-out parameter of table of record:
TYPE RECORD_TYP IS RECORD (
CAT_CD VARCHAR2(4),
MOD_ID NUMBER(6)
);
I found this example that talks about List<String>
and List<Integer>
:
http://viralpatel.net/blogs/java-passing-array-to-oracle-stored-procedure/.
But what about List<MyRecordDTO>
?
EDIT: I found an answer here where the poster used an oracle.sql.STRUCT type.
http://betteratoracle.com/posts/32-passing-arrays-of-record-types-between-oracle-and-java
Using this example, I found the exception java.sql.SQLException: Internal Error: Inconsistent catalog view
. Googling this exception, I called the DBA to grant me access to "RECORD_TYP
"
java oracle
add a comment |
I'm trying to execute an oracle stored procedure that has an in-out parameter of table of record:
TYPE RECORD_TYP IS RECORD (
CAT_CD VARCHAR2(4),
MOD_ID NUMBER(6)
);
I found this example that talks about List<String>
and List<Integer>
:
http://viralpatel.net/blogs/java-passing-array-to-oracle-stored-procedure/.
But what about List<MyRecordDTO>
?
EDIT: I found an answer here where the poster used an oracle.sql.STRUCT type.
http://betteratoracle.com/posts/32-passing-arrays-of-record-types-between-oracle-and-java
Using this example, I found the exception java.sql.SQLException: Internal Error: Inconsistent catalog view
. Googling this exception, I called the DBA to grant me access to "RECORD_TYP
"
java oracle
convert the returned jdbc array construct to aList<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.
– jtahlborn
Sep 12 '12 at 18:07
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15
add a comment |
I'm trying to execute an oracle stored procedure that has an in-out parameter of table of record:
TYPE RECORD_TYP IS RECORD (
CAT_CD VARCHAR2(4),
MOD_ID NUMBER(6)
);
I found this example that talks about List<String>
and List<Integer>
:
http://viralpatel.net/blogs/java-passing-array-to-oracle-stored-procedure/.
But what about List<MyRecordDTO>
?
EDIT: I found an answer here where the poster used an oracle.sql.STRUCT type.
http://betteratoracle.com/posts/32-passing-arrays-of-record-types-between-oracle-and-java
Using this example, I found the exception java.sql.SQLException: Internal Error: Inconsistent catalog view
. Googling this exception, I called the DBA to grant me access to "RECORD_TYP
"
java oracle
I'm trying to execute an oracle stored procedure that has an in-out parameter of table of record:
TYPE RECORD_TYP IS RECORD (
CAT_CD VARCHAR2(4),
MOD_ID NUMBER(6)
);
I found this example that talks about List<String>
and List<Integer>
:
http://viralpatel.net/blogs/java-passing-array-to-oracle-stored-procedure/.
But what about List<MyRecordDTO>
?
EDIT: I found an answer here where the poster used an oracle.sql.STRUCT type.
http://betteratoracle.com/posts/32-passing-arrays-of-record-types-between-oracle-and-java
Using this example, I found the exception java.sql.SQLException: Internal Error: Inconsistent catalog view
. Googling this exception, I called the DBA to grant me access to "RECORD_TYP
"
java oracle
java oracle
edited Sep 13 '12 at 9:27
bouhmid_tun
asked Sep 12 '12 at 17:14
bouhmid_tunbouhmid_tun
149317
149317
convert the returned jdbc array construct to aList<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.
– jtahlborn
Sep 12 '12 at 18:07
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15
add a comment |
convert the returned jdbc array construct to aList<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.
– jtahlborn
Sep 12 '12 at 18:07
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15
convert the returned jdbc array construct to a
List<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.– jtahlborn
Sep 12 '12 at 18:07
convert the returned jdbc array construct to a
List<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.– jtahlborn
Sep 12 '12 at 18:07
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15
add a comment |
1 Answer
1
active
oldest
votes
I know this is a very old question. But I hope this helps.
Here I am passing a Custom Type Array and in return expecting a Custom type Array.
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object objects = (Object)outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12393268%2fexecuting-a-stored-procedure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I know this is a very old question. But I hope this helps.
Here I am passing a Custom Type Array and in return expecting a Custom type Array.
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object objects = (Object)outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}
add a comment |
I know this is a very old question. But I hope this helps.
Here I am passing a Custom Type Array and in return expecting a Custom type Array.
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object objects = (Object)outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}
add a comment |
I know this is a very old question. But I hope this helps.
Here I am passing a Custom Type Array and in return expecting a Custom type Array.
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object objects = (Object)outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}
I know this is a very old question. But I hope this helps.
Here I am passing a Custom Type Array and in return expecting a Custom type Array.
myJavaRequest req = new myJavaRequest();
req.setEmpId("940006614");
myJavaReqArray[0] = req;
List<myJavaResp> myJavaRespLst = new ArrayList<myJavaResp>();
try {
//fetch connection (this should be a OracleConnection class).
OracleConnection oraConn = (OracleConnection) getConnectionFromDB();
//Set the mappings -- what is the SQL Object type to Java class mappings when it comes to response.
Map map = oraConn.getTypeMap();
map.put("MYSCHEMA.SQLRESPDTO", Class.forName("com.myhome.myJavaResp"));
//Create the Array descriptor for the input array
ArrayDescriptor inputArrayDescr = ArrayDescriptor.createDescriptor("MYSCHEMA.MYREQDTOLIST", oraConn);
ARRAY inputArray = new ARRAY(inputArrayDescr, oraConn, spgPrefReqArray); //This is an Oracle ARRAY
//Prepare the Stored procedure call
OracleCallableStatement stmt = (OracleCallableStatement)oraConn.prepareCall("{ ? = call MYSCHEMA.PKG.SOME_SP(?) }");
stmt.registerOutParameter(1, OracleTypes.ARRAY, "MYSCHEMA.SQLRESPDTOLIST");
stmt.setArray(2, inputArray);
//Lets execute
stmt.execute();
//Fetch the Array of Objects that will have the set of expecting response java objects.
ARRAY outArray = ((OracleCallableStatement)stmt).getARRAY(1);
Object objects = (Object)outArray.getArray(map);
if(null != objects && objects.length > 0){
for(int iIndex=0; iIndex<objects.length; iIndex++){
myJavaRespLst.add((myJavaResp)objects[iIndex]);
}
}
}
edited Jul 4 '14 at 16:11
gipinani
8,78584370
8,78584370
answered Jul 4 '14 at 15:50
user3770241user3770241
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12393268%2fexecuting-a-stored-procedure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
convert the returned jdbc array construct to a
List<MyRecordDTO>
. nothing in jdbc will do arbitrary value to POJO conversion for you.– jtahlborn
Sep 12 '12 at 18:07
In fact, the List<MyRecordDTO> is an INOUT parameter and I'm unable to pass this parameter.
– bouhmid_tun
Sep 12 '12 at 18:18
So basically, the last paragraph (about granting access to RECORD_TYP) is the answer to the question.
– David Balažic
Mar 28 '18 at 13:15