Error while executing java stored procedure from a pl/sql procedure
We have a requirement where we need to execute JAVA code stored in an Oracle database (Java Stored Procedure). This code uses some JAR files which we have already loaded without any errors in the database.
The class file was also loaded in the database without any errors. But when we execute the method of this class (JAVA code), it gives the following error:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NoClassDefFoundError
Is there any way of debugging the code and getting to know where exactly the problem is? Or, any tool/software available for doing the same.
Any pointers would be of great help!
Thanks in advance
Hi Uday,
My guess is that there is a problem with your java stored procedure that is causing the "ExceptionInInitializer" error to be thrown. According to the javadoc:
is thrown to indicate that an exception occurred during
evaluation of a static initializer or
the initializer for a static variable
Since I didn't see any of your code in your post, I can't help you much more, I'm afraid. Perhaps if you would provide some more details, I may be able to help you some more. I think the following details would be helpful:
1. Complete error message and stack trace you are getting.
2. The section of your java code that you think is causing the problem.
3. Oracle database version you are using.
Good Luck,
Avi.
Similar Messages
-
Error while executing Java Stored Procedure.
Hi,
When I'm trying to execute my java stored procedure i'm getting the following error:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.ExceptionInInitializerError
Does anybody has idea why this error comes and how can be resolved.
Thanks in advance.
UdayHi Uday,
My guess is that there is a problem with your java stored procedure that is causing the "ExceptionInInitializer" error to be thrown. According to the javadoc:
is thrown to indicate that an exception occurred during
evaluation of a static initializer or
the initializer for a static variable
Since I didn't see any of your code in your post, I can't help you much more, I'm afraid. Perhaps if you would provide some more details, I may be able to help you some more. I think the following details would be helpful:
1. Complete error message and stack trace you are getting.
2. The section of your java code that you think is causing the problem.
3. Oracle database version you are using.
Good Luck,
Avi. -
Strange error while executing a stored procedure: Incorrect syntax near '@p0'
All, I am getting a strange error while executing a stored procedure: Incorrect syntax near '@p0' using JDBC CallableStatment.
Here is my code...
CallableStatement cStmt = con.prepareCall("{call SET CHAINED ON EXEC <dbName>.<schemaName>.<SPName> (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
cStmt.setString(1, "2012005881");
cStmt.setString(2, "07");
cStmt.setString(3, "10");
cStmt.setString(4, "Case title");
cStmt.setString(5, "Open");
java.sql.Date dt1 = new java.sql.Date(2014,10,20);
cStmt.setDate(6, dt1);
cStmt.setString(7, "01");
cStmt.setString(8, "N");
cStmt.setString(9, "ADA Test");
cStmt.setString(10, "N");
cStmt.setString(11, "English");
cStmt.setString(12, "N");
cStmt.setString(13, "N");
cStmt.setString(14, "N");
cStmt.setString(15, "N");
cStmt.setString(16, "N");
cStmt.setString(17, "N");
cStmt.setString(18, "07");
cStmt.setString(19, "10");
cStmt.setString(20, "juache0");
java.sql.Date dt2 = new java.sql.Date(2014,10,20);
java.sql.Date dt3 = new java.sql.Date(2014,10,20);
cStmt.setDate(21, dt2);
cStmt.setDate(22, dt3);
cStmt.setString(23, "userid0");
cStmt.setString(24, "");
cStmt.setString(25, "");
cStmt.setString(26, "");
java.math.BigDecimal bg1 = new java.math.BigDecimal(10);
cStmt.setBigDecimal(27, bg1);
cStmt.setString(28, "userid");
cStmt.setString(29, "userid");
int hadResults = cStmt.executeUpdate();
Your help is greatly appreciated.
I am executing the above using Jconnect3.0 driver, inside WebSphere Application Server V8.0
Thanks
NagsNOTE: I don't work with JDBC/jConnect so (at this point) just some questions ...
1 - are you sending this to ASE, ASA, IQ, or some other RDBMS?
2 - what is the value of <schemaname>?
3 - do you have other prepareCall() instances that successfully call a stored proc? [would be interesting to see if there's a difference in the format of the calls]
A quick google search shows a couple ways to submit a stored proc execution to the RDBMS, with the format depending on the format expected by the target RDBMS.
I'm wondering if you really need/want the parentheses around the argument list, ie, what happens if you change
from
-- parentheses around args
EXEC <dbName>.<schemaName>.<SPName> ( ?,?,?,?,?,...,? )
to
-- no parentheses around args
EXEC <dbName>.<schemaName>.<SPName> ?,?,?,?,?,...,?
In ASE if I wrap the parameters in parentheses I get the same error you're getting:
================== w/ parentheses => error
1> sp_who (sa)
2> go
Msg 102, Level 15, State 1:
Server 'CC1_V1', Line 1:
Incorrect syntax near 'sa'. <<=== sa == @p0 ??
================== w/out parentheses => works
1> sp_who sa
2> go
fid spid status loginame origname ...
0 17 running sa sa ...
================== -
Error while executing the stored procedure through sender JDBC adapter
Hi All,
I am getting below error while executing the stored procedure through sender JDBC adapter.
Database-level error reported by JDBC driver while executing statement 'exec SapgetNextEntity 'SalesOrder''. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
what is the problem? any idea to anyone...
regards
Rameshhi Dharamveer,
I am not getting below statement for your reply
Try to use Refrence Cursor it will return u reference of resultset.
I mention SP like this
exec SapgetNextEntity 'SalesOrder'
SapgetNextEntity -
> SP Name
SalesOrder----
> Parameter I am passing...
regards
Ramesh -
Error while executing a stored procedure from forms6i
When I execute a STORED PROCEDURE from ORACLE DB 10g this procedure works perfectly fine.
But when I execute the same from the FORMs 6i I get the following error:
PDE-PLU022 Don't have access to the stored program unit
XMLPARSERCOVER in schema CARE.
where XMLPARSERCOVER is the class and
CARE is the schema.
Regards,
Jignesh SI have tried this with both the owner of the schema and the intended user, -from both forms and directly.
All rights was granted on the stored procedure. Since posting I have found that one of the tables that the procedure might insert into, was not explicitly granted to the intended user, and after rectifying that the error message went away.
-however, the procedure now silently "finishes" without any evidence that it ever ran, if invoked from the forms application. When invoked from SQL Plus (or JDev, or Toad) it runs as expected.
I have no public synonym for the procedure, -is that necessary?
The stored procedure in question is implemented in java, and published as a stored procedure. It does rather heavy lifting, when running, using a view against another server , updating local tables and quite a lot of data validation/cleansing, and logging. All recourses are within the same schema.
Any ideas? -
While executing java stored procedure i got an error
I have used this command to load java source into data base
loadjava -user ENCORA/ENCORA C:\framework\Packages\testdevelopement\HOST.java
but while executing i got an error.
SQL> create or replace function run_cmd(p_cmd in varchar2) return number
2 as
3 language java
4 name 'HOST.RunThis(java.lang.String[]) return integer';
5 /
Function created.
SQL> create or replace procedure RC(p_cmd in varchar2)
2 as
3 x number;
4 begin
5 x := run_cmd(p_cmd);
6 end;
7 /
Procedure created.
SQL> set serveroutput on size 1000000
SQL> exec dbms_java.set_output(1000000)
PL/SQL procedure successfully completed.
SQL> exec rc('/usr/bin/ps -ef');
BEGIN rc('/usr/bin/ps -ef'); END;
ERROR at line 1:
ORA-29540: class HOST does not exist
ORA-06512: at "ENCORA.RUN_CMD", line 0
ORA-06512: at "ENCORA.RC", line 5
ORA-06512: at line 1
can any one suggest me how can i resolve this problem?Hi Uday,
My guess is that there is a problem with your java stored procedure that is causing the "ExceptionInInitializer" error to be thrown. According to the javadoc:
is thrown to indicate that an exception occurred during
evaluation of a static initializer or
the initializer for a static variable
Since I didn't see any of your code in your post, I can't help you much more, I'm afraid. Perhaps if you would provide some more details, I may be able to help you some more. I think the following details would be helpful:
1. Complete error message and stack trace you are getting.
2. The section of your java code that you think is causing the problem.
3. Oracle database version you are using.
Good Luck,
Avi. -
Error while executing Multiple Stored Procedure through .sql file
Hi Guru's.
I am new to ORACLE. I am facing problem while creating Stored Procedure through .sql file.
I have one test.sql file with Stored Procedure is like,
CREATE OR REPLACE PROCEDURE skeleton1
AS
BEGIN
DBMS_Output.Put_Line('skeleton1');
END skeleton1;
CREATE OR REPLACE PROCEDURE skeleton2
AS
BEGIN
DBMS_Output.Put_Line('skeleton2');
END skeleton2;
Now when i try to execute this test.sql file through SQL PLUS it gives me Error like this
I am opening test.sql file from SQL PLUS,
SQL>
1 CREATE OR REPLACE PROCEDURE skeleton1
2 AS
3 BEGIN
4 DBMS_Output.Put_Line('skeleton1');
5 END skeleton1;
6 /
7 CREATE OR REPLACE PROCEDURE skeleton2
8 AS
9 BEGIN
10 DBMS_Output.Put_Line('skeleton2');
11* END skeleton2;
SQL> /
Warning: Procedure created with compilation errors.
SQL> show errors;
Errors for PROCEDURE SKELETON1:
LINE/COL ERROR
6/1 PLS-00103: Encountered the symbol "/"
SQL>
Please suggest how to create multiple CREATE PROCEDURE using single .sql script file....
Regards,
ShatrughanHi,
Try this
CREATE OR REPLACE PROCEDURE skeleton1
AS
BEGIN
DBMS_Output.Put_Line('skeleton1');
END ;
CREATE OR REPLACE PROCEDURE skeleton2
AS
BEGIN
DBMS_Output.Put_Line('skeleton2');
END;
/Save the file and call it.
Regards,
Bhushan -
Error while executing the stored procedure
Hi All,
When I try to execute the store procedure .The store procedure does not have parameter. I am getting the following error. The store procedure has been successfully complied.
Thanks for all your help.
uday
ORA-01422: exact fetch returns more than requested number of rows
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requestedHi All,
Here is the store proc and version. I do not have much exposure to pl sql store proc .
Thanks for all your support and help.
uday
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production"
TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Here is the store proc .
create or replace
PROCEDURE TEST AS
R_REGION VARCHAR2(5);
R_listing2rifs_count number;
R_listing2rifs number;
listing2iag_count number; /* mentioned already: rp0428 */
listing2iag number;
R_rod2iag_count number;
R_rod2iagnumber;
R_rod2ra_count number;
R_rod2ra number;
begin
select Region,
sum(listing2rifs_count) as listing2rifs_count,
round((sum(listing2rifs) / sum(listing2rifs_count))/30.4,1) as listing2rifs,
sum(listing2iag_count) as listing2iag_count,
round((sum(listing2iag) / sum(listing2iag_count))/30.4,1) as listing2iag,
sum(rod2iag_count) as rod2iag_count,
round((sum(rod2iag) / sum(rod2iag_count))/30.4,1) as rod2iag,
sum(rod2ra_count) as rod2ra_count,
round((sum(rod2ra) / sum(rod2ra_count))/30.4,1) as rod2ra
into R_REGION,R_listing2rifs_count,R_listing2rifs,listing2iag_count,listing2iag,
R_rod2iag_count,R_rod2iag,R_rod2ra_count,R_rod2ra
from (select site.FK_REF_REGION_CODE Region,
site.site_id,
site.EPA_ID,
site.name site_name,
FEDERAL_FACILITY_DETER_CODE,
NPL_STATUS_CODE,
site.BRAC_TYPE_NAME,
sis.FT_FLAG,
listing_action,
rifs_action,
iag_action,
rod_action,
ra_action,
listing.ACTUAL_COMPLETION_DATE as listing_date,
iag.ACTUAL_COMPLETION_DATE as iag_date,
first_rifs.ACTUAL_START_DATE as first_rifs_start_date,
first_rod.ACTUAL_COMPLETION_DATE as first_rod_date,
ra_start.ACTUAL_START_DATE as first_ra_start_date,
case when first_rifs.ACTUAL_START_DATE is not null
and listing.ACTUAL_COMPLETION_DATE is not null
then 1
else 0
end as listing2rifs_count,
first_rifs.ACTUAL_START_DATE - listing.ACTUAL_COMPLETION_DATE as listing2rifs,
case when first_rifs.ACTUAL_START_DATE is not null
and listing.ACTUAL_COMPLETION_DATE is not null
then 1
else 0
end as listing2iag_count,
iag.ACTUAL_COMPLETION_DATE - listing.ACTUAL_COMPLETION_DATE as listing2iag,
case when first_rifs.ACTUAL_START_DATE is not null
and listing.ACTUAL_COMPLETION_DATE is not null
then 1
else 0
end as rod2iag_count,
iag.ACTUAL_COMPLETION_DATE - first_rod.ACTUAL_COMPLETION_DATE as rod2iag,
case when first_rifs.ACTUAL_START_DATE is not null
and listing.ACTUAL_COMPLETION_DATE is not null
then 1
else 0
end as rod2ra_count,
ra_start.ACTUAL_START_DATE - first_rod.ACTUAL_COMPLETION_DATE as rod2ra
from site
LEFT OUTER JOIN
(select fk_site_id,
SPECIAL_INITIATIVE_CODE as FT_FLAG
from SPECIAL_INITIATIVE_SITE sppi
where SPECIAL_INITIATIVE_CODE = 'FT'
) SIS
ON site.site_id = sis.fk_site_id
LEFT OUTER JOIN
(select fk_site_id,
TYPE_SEQUENCE_CODE as listing_action,
ACTUAL_COMPLETION_DATE
from action
where TYPE_CODE = 'NF'
and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
and ACTUAL_COMPLETION_DATE is not null
and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
(SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
from action b
WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
and b.TYPE_CODE = 'NF'
and b.ACTUAL_COMPLETION_DATE is not null
) listing
ON SITE.SITE_ID = LISTING.FK_site_id
LEFT OUTER JOIN
(select FK_site_id,
TYPE_SEQUENCE_CODE as rifs_action,
ACTUAL_START_DATE,
ACTUAL_COMPLETION_DATE
from action
where TYPE_CODE in ('NH','LW') /*('RI','NA','NH','FS','NK','NI','CO','BD','LW') */
and LEAD_CODE = 'FF'
and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PS','PB','OA','OS','TN','TT'))
and ACTUAL_START_DATE is not null
and TO_CHAR(action.ACTUAL_START_DATE,'YYYYMMDD') || TYPE_SEQUENCE_CODE =
(SELECT min(TO_CHAR(ACTUAL_START_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
from action b
WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
and b.TYPE_CODE in ('NH','LW') /*('RI','NA','NH','FS','NK','NI','CO','BD','LW') */
and b.ACTUAL_START_DATE is not null
) first_rifs
ON site.site_id = first_rifs.FK_site_id
LEFT OUTER JOIN
(select FK_site_id,
TYPE_SEQUENCE_CODE as iag_action,
ACTUAL_COMPLETION_DATE
from action
where TYPE_CODE = 'FI'
and action.LEAD_CODE = 'FE'
and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
and ACTUAL_COMPLETION_DATE is not null
and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
(SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
from action b
WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
and b.TYPE_CODE = 'FI'
and b.ACTUAL_COMPLETION_DATE is not null
) iag
ON site.site_id = iag.FK_site_id
LEFT OUTER JOIN
(select FK_site_id,
TYPE_SEQUENCE_CODE as rod_action,
ACTUAL_COMPLETION_DATE
from action
where TYPE_CODE = 'RO'
and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PC','PB','OA','OC','TO','TT'))
and ACTUAL_COMPLETION_DATE is not null
and TO_CHAR(action.ACTUAL_COMPLETION_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
(SELECT min(TO_CHAR(ACTUAL_COMPLETION_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
from action b
WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
and b.TYPE_CODE = 'RO'
and b.ACTUAL_COMPLETION_DATE is not null
) first_rod
ON site.site_id = first_rod.FK_site_id
LEFT OUTER JOIN
(select FK_site_id,
TYPE_SEQUENCE_CODE as ra_action,
ACTUAL_START_DATE
from action
where TYPE_CODE = 'LY'
and (ANOMALY_CODE is null or ANOMALY_CODE not in ('PS','PB','OA','OS','TN','TT'))
and ACTUAL_START_DATE is not null
and TO_CHAR(action.ACTUAL_START_DATE,'YYYYMMDD') || action.TYPE_SEQUENCE_CODE =
(SELECT min(TO_CHAR(ACTUAL_START_DATE,'YYYYMMDD') || B.TYPE_SEQUENCE_CODE)
from action b
WHERE ACTION.FK_SITE_ID = b.FK_Site_ID
and b.TYPE_CODE = 'LY'
and b.ACTUAL_START_DATE is not null
) ra_start
ON site.site_id = ra_start.FK_site_id
WHERE site.FEDERAL_FACILITY_DETER_CODE = 'Y'
and site.NPL_STATUS_CODE in (/*'P',*/'F','D','A')
) durations
group by Region
order by 1;
end;
errors:
ORA-01422: exact fetch returns more than requested number of rows
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested -
Can we call a Java Stored Proc from a PL/SQL stored Proc?
Hello!
Do you know how to call a Java Stored Proc from a PL/SQL stored Proc? is it possible? Could you give me an exemple?
If yes, in that java stored proc, can we do a call to an EJB running in a remote iAS ?
Thank you!For the java stored proc called from pl/sql, the example above that uses dynamic sql should word :
CREATE OR REPLACE PACKAGE MyPackage AS
TYPE Ref_Cursor_t IS REF CURSOR;
FUNCTION get_good_ids RETURN VARCHAR2 ;
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t;
END MyPackage;
CREATE OR REPLACE PACKAGE BODY MyPackage AS
FUNCTION get_good_ids RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'MyServer.getGoodIds() return java.lang.String';
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t
IS table_cursor Ref_Cursor_t;
good_ids VARCHAR2(100);
BEGIN
good_ids := get_good_ids();
OPEN table_cursor FOR 'SELECT id, name FROM TableA WHERE id IN ( ' | | good_ids | | ')';
RETURN table_cursor;
END;
END MyPackage;
public class MyServer{
public static String getGoodIds() throws SQLException {
return "1, 3, 6 ";
null -
Error ORA-04031 while executing a stored procedure from Pro C++ code
I am getting the error ORA-04031(Unable to allocate 4096 bytes of shared memory("Shared Pool",.....)) while trying to execute a stored procedure from my pro*C application. This happens only after a few hours since the application has been running. I am closing the cursor after every database call.
Does anyone know why it is happening and any possible solutions?
TIA
Srithaj.One thing that can be done is to flush the shared pool before starting the application.
alter system flush shared pool;
Another is to increase the shared pool size by setting the parameter shared_pool_size in init_sid.ora file.
null -
Missing Defines Error in Simple Java Stored Procedure
Anyone have any suggestions on what might be causing the unusual behavior described below? Could it be a 10g java configuration issue? I am really stuck so I'm open to just about anything. Thanks in advance.
I am writing a java stored procedure and am getting some SQLException's when executing some basic JDBC code from within the database. I reproduced the problem by writing a very simple java stored procedure which I have included below. The code executes just fine when executed outside of the database (10g). Here is the output from that execution:
java.class.path=C:\Program Files\jEdit42\jedit.jar
java.class.version=48.0
java.home=C:\j2sdk1.4.2_04\jre
java.vendor=Sun Microsystems Inc.
java.version=1.4.2_04
os.arch=x86
os.name=Windows XP
os.version=5.1
In getConnection
Executing outside of the DB
Driver Name = Oracle JDBC driver
Driver Version = 10.1.0.2.0
column count=1
column name=TEST
column type=1
TEST
When I execute it on the database by calling the stored procedure I get:
java.class.path=
java.class.version=46.0
java.home=/space/oracle/javavm/
java.vendor=Oracle Corporation
java.version=1.4.1
os.arch=sparc
os.name=Solaris
os.version=5.8
In getConnection
We are executing inside the database
Driver Name = Oracle JDBC driver
Driver Version = 10.1.0.2.0
column count=1
column name='TEST'
column type=1
MEssage: Missing defines
Error Code: 17021
SQL State: null
java.sql.SQLException: Missing defines
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.OracleResultSetImpl.getString(Native Method)
at OracleJSPTest.test(OracleJSPTest:70)
Here is the Java code:
// JDBC classes
import java.sql.*;
import java.util.*;
//Oracle Extensions to JDBC
import oracle.jdbc.*;
import oracle.jdbc.driver.OracleDriver;
public class OracleJSPTest {
private static void printProperties(){
System.out.println("java.class.path="+System.getProperty("java.class.path"));
System.out.println("java.class.version="+System.getProperty("java.class.version"));
System.out.println("java.home="+System.getProperty("java.home"));
System.out.println("java.vendor="+System.getProperty("java.vendor"));
System.out.println("java.version="+System.getProperty("java.version"));
System.out.println("os.arch="+System.getProperty("os.arch"));
System.out.println("os.name="+System.getProperty("os.name"));
System.out.println("os.version="+System.getProperty("os.version"));
private static Connection getConnection() throws SQLException {
System.out.println("In getConnection");
Connection connection = null;
// Get a Default Database Connection using Server Side JDBC Driver.
// Note : This class will be loaded on the Database Server and hence use a
// Server Side JDBC Driver to get default Connection to Database
if(System.getProperty("oracle.jserver.version") != null){
System.out.println("We are executing inside the database");
//connection = DriverManager.getConnection("jdbc:default:connection:");
connection = new OracleDriver().defaultConnection();
}else{
System.out.println("Executing outside of the DB");
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
connection = DriverManager.getConnection("jdbc:oracle:thin:@XXX.XXX.XXX.XX:XXXX:XXXX","username","password");
DatabaseMetaData dbmeta = connection.getMetaData();
System.out.println("Driver Name = "+ dbmeta.getDriverName());
System.out.println("Driver Version = "+ dbmeta.getDriverVersion());
return connection;
public static void main(String args[]){
test();
public static void test() {
printProperties();
Connection connection = null; // Database connection object
try {
connection = getConnection();
String sql = "select 'TEST' from dual";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData meta = rs.getMetaData();
System.out.println("column count="+meta.getColumnCount());
System.out.println("column name="+meta.getColumnName(1));
System.out.println("column type="+meta.getColumnType(1));
if(rs.next()){
System.out.println(rs.getString(1));
} catch (SQLException ex) { // Trap SQL Errors
System.out.println("MEssage: " + ex.getMessage());
System.out.println("Error Code: " + ex.getErrorCode());
System.out.println("SQL State: " + ex.getSQLState());
ex.printStackTrace();
} finally {
try{
if (connection != null || !connection.isClosed())
connection.close(); // Close the database connection
} catch(SQLException ex){
ex.printStackTrace();
Message was edited by:
jason_macJason,
Works for me on Oracle 10.1.0.3 running on Red Hat Enterprise Linux AS release 3 (Taroon).
Java code:
import java.sql.*;
* Oracle Java Virtual Machine (OJVM) test class.
public class OjvmTest {
public static void test() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement("select 'TEST' from SYS.DUAL");
rs = ps.executeQuery();
if (rs.next()) {
System.out.println(rs.getString(1));
finally {
if (rs != null) {
try {
rs.close();
catch (SQLException sqlEx) {
System.err.println("Error ignored. Failed to close result set.");
if (ps != null) {
try {
ps.close();
catch (SQLException sqlEx) {
System.err.println("Error ignored. Failed to close statement.");
}And my PL/SQL wrapper:
create or replace procedure P_J_TEST as language java
name 'OjvmTest.test()';And here is how I execute it in a SQL*Plus session:
set serveroutput on
exec dbms_java.set_output(2000)
exec p_j_testGood Luck,
Avi. -
No method found error when calling java stored procedured
hi:
i am rather confused about this. i have written several
java stored procedures and all of them work fine. but when i tried another one , the error message 'no method found 'occurs
when i call the procedure from sqlplus.
it' s a simple procedure . but it's very strange and happens
from time to time
my compile shell as following
javac -classpath $ORACLE_HOME/jdbc/lib/classes12.zip GenFiles.java
$ORACLE_HOME/bin/loadjava -u zw/zw@aixtest GenFiles.class
and
my definition as following
create or replace procedure files(chargeCyckeID varchar2, cycleStart varchar2,cycleEnd varchar2,
loginName varchar2, filePath varchar2, start1 number, end1 number, step number)
AS LANGUAGE JAVA
NAME 'GenFiles.genFile(String , String , String , String , String , int , int , int )';
and my java code is here :
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
public class GenFiles{
public static void main(String[] args){
04UU<F7QV\FZ#,V\FZ?*J<#,V\FZ=aJx#,5GB<C{#, ND<~B7>6#,Pr:E?*J<#,Pr:E=aJx#,2=3$#(Iz3IND<~5D<GB<J}#)
public static void genFile(String chargeCycleID, String cycleStart, String cycleEnd, String loginName, String filePath, int start, int end, int step){
try{
String sqllist = "select customer_id,contract_code, usercode,ani,ord,"
+ " agent_code,linkman, customer_name , postcode,paymethod_category_id ,"
+ " ltrim(to_char(cost,'999999990.99')) cost,call_duration,from listani_file where ord> ? and ord<? order by contract_code";
String sqlcalls1 = "select a.ani || ',' || a.PASS || ',' || to_char(a.START_TIME,'yyyy-mm-dd hh24:mi:ss') stime || ',' || trunc(a.CALL_DURATION/60)||':'||ltrim(to_char(mod(a.CALL_DURATION,60),'09')) CALL_DURATION || ',' || ltrim(to_char((CALL_AMOUNT/ceil(CALL_DURATION/60)),'999999990.99')) RATE || ',' || ltrim(to_char(a.CALL_AMOUNT,'999999990.99')) CALL_AMOUNT"
+" from call_fact_mind a "
+" where a.usercode=?"
+ " and a.ani=? "
+ " and a.period_key<='" + end + "'"
+ " and a.period_key>='" + start + "'"
+ " and a.charge_flag='Y' "
+ " and a.CALL_DURATION>6"
+ " and a.CALL_AMOUNT>0"
+" order by a.period_key";
String sqlcalls2 = "select a.ani || ',' || a.PASS || ',' || to_char(a.START_TIME,'yyyy-mm-dd hh24:mi:ss') stime || ',' || trunc(a.CALL_DURATION/60)||':'||ltrim(to_char(mod(a.CALL_DURATION,60),'09')) CALL_DURATION || ',' || ltrim(to_char((CALL_AMOUNT/ceil(CALL_DURATION/60)),'999999990.99')) RATE || ',' || ltrim(to_char(a.CALL_AMOUNT,'999999990.99')) CALL_AMOUNT "
+ " from call_fact_mind a "
+ " where a.usercode=?"
+ " and a.period_key<='" + end + "'"
+ " and a.period_key>='" + start + "'"
+ " and a.charge_flag='Y' "
+ " and a.CALL_DURATION>6"
+ " and a.CALL_AMOUNT>0"
+" order by a.period_key";
Connection con = new OracleDriver().defaultConnection();
try{
int i = start;
//8y>]2=3$Q-;7
while( true){
if( i>=end ) break;
genFile(con, i , i+step, chargeCycleID, loginName, filePath, sqllist, sqlcalls1, sqlcalls2);
i += step;
}catch(Exception ex){
}finally{
if( con != null) con.close();
}catch(Exception exx){}
8y>]2=3$Iz3IND<~
private static void genFile(Connection con, int start, int end, String chargeCycleID, String loginName, String filePath, String sqllist, String sqlcalls1, String sqlcalls2) throws Exception{
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
PreparedStatement ps3 = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
String fileName = filePath + System.getProperty("file.separator") + start + "_" + end + ".txt";
BufferedWriter writer = null;
try{
writer = new BufferedWriter(new FileWriter(fileName));
ps1 = con.prepareStatement(sqllist);
ps2 = con.prepareStatement(sqlcalls1);
ps3 = con.prepareStatement(sqlcalls2);
ps1.setInt(1, start);
ps1.setInt(2, end);
rs1 = ps1.executeQuery();
//Iz3Ibuffer,V;SPR;6(<GB<J12EP4HkND<~
StringBuffer strBuffer = new StringBuffer();
int i =0;
//Q-;7:OM,=a9{</
String preContractCode = "";
String currentContractCode = "";
while( rs1.next()){
currentContractCode = rs1.getString("contract_code");
if( rs1.getString("ani") == null){
ps2.setString( 1, rs1.getString("usercode"));
rs2 = ps2.executeQuery();
}else{
ps1.setString(1, rs1.getString("usercode"));
ps1.setString(2, rs1.getString("ani"));
rs2 = ps1.executeQuery();
//Hg9{3vOVPB5D:OM,:E#,<SHk:OM,OnM7,contract_costJG:OM,On7QSC
if( ! preContractCode.equals(currentContractCode)){
//TZG0Cf<SHk?UPP
strBuffer.append("\r\n");
String contractHead = "\"1\"" + ",\"" + rs1.getString("linkman") + "\",\"" + rs1.getString("customer_name")
+ "\",\"" + rs1.getString("contract_code") + "\",\"" + rs1.getString("agent_code")
+ "\",\"" + chargeCycleID + "\",\"" + rs1.getString("contract_cost") + "\"";
strBuffer.append(contractHead);
while( rs2.next()){
if( i<1000){
i++;
strBuffer.append("\"2\"" + rs2.getString(1));
}else{
String str = strBuffer.toString();
writer.write(str, 0, str.length());
strBuffer = new StringBuffer();
strBuffer.append(rs2.getString(1));
i = 1;
//<SHk7QSC:O<F
if( rs1.getString("ani") == null){
String trail = "\"2\"" + ",\"" + "ani: " + "\",\"" + rs1.getString("ani") + "\",\"" + "Total Amount: " + "\",\"" + rs1.getString("cost") + "\"\r\n";
strBuffer.append(trail);
}else{
String trail = "\"2\"" + ",\"" + "usercode: " + "\",\"" + rs1.getString("usercode") + "\",\"" + "Total Amount: " + "\",\"" + rs1.getString("cost") + "\"\r\n";
strBuffer.append(trail);
preContractCode = currentContractCode;
writer.close();
rs2.close();
}catch(Exception ex){
}finally{
if( rs1 != null) rs1.close();
if( rs2 != null) rs2.close();
if( ps1 != null) ps1.close();
if( ps2 != null) ps2.close();
i need your help!
regards
daniel wangHi again, Daniel,
I'm only guessing here, but unless you've made lots of mistakes when
you copied your code to your post to the forum, your method signatures
don't match. The definition of "genFile" in your java class is quite
different to what you wrote in your PL/SQL wrapper.
Also, you have defined "genFile" to be a private method -- I think it
needs to be public.
Also, I think the "main" method doesn't need to be in the "GenFiles"
class -- perhaps you should remove it.
Also, I think in your PL/SQL wrapper you need to use fully qualified
names, so use "java.lang.String" and not just "String".
Lastly, I think you should use the "-force" and "-resolve" flags
with the "loadjava" command.
Good Luck,
Avi. -
Error while calling a stored procedure with OUT parameter.
Hi,
I am trying to call a Stored Procedure(SP) with an OUT parameter(Ref Cursor) from a third party tool. It is called using OLE-DB Data provider. In one database the procedure works fine but when I change the database the procedure call is giving following error.
Distribution Object: COM Error. COM Source: OraOLEDB. COM Error message: IDispatch error #3092. COM Description: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored.
I am not able to find as to why is this happening. Please let me know any clues /help to solve this problem.
Thanks in advance.If you're using Oracle Provider for OLE DB (OraOLEDB) to execute this stored procedure, you need to set PLSQLRSet attribute. This attribute can be set in registry, connection string, or command object. Please refer to User Documentation for more information.
-
Geeting TIMEOUT while executing a Stored Procedure.
Hi Gurus,
Am facing a TimeOut issue while executing the Sql Stored Procedure.
I have changed a settings of Execution TimeOut to Zero (which is unlimited ), Am still unable to execute the Stored Procedure.
Should i have to add any TimeOut Command in my Sql Stored Procedure. If please suggest me.
Thanks in advance.Time out is the client who throws the error not SQL Server. Please read Erland's article
http://www.sommarskog.se/query-plan-mysteries.html
Are you sure there is blocking/locking? Is that possible someone run BEGIN TRAN and did not properly specify COMMIT TRAN?
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
21700 while calling java stored procedure in 9i
I create a java stored procedure that takes a varray of a rowtype. When I call that procedure, I get an ora-21700. If I remove the varray from the parameter list, I can call the procedure okay. My goal is to create a generic java procedure that can take a rowtype from any table and create XML. Once I get the oracle.sql.ARRAY into my code, I am okay. I just can't seem to pass it in. I have pasted my code below:
Java:
import oracle.sql.*;
public class test {
public static String sayHello() {
return("Hello, World!");
public static void genXML(oracle.sql.ARRAY a, oracle.sql.CLOB c) throws Exce
ption {
c.putString(1,"<test>This is a test!</test>");
PL/SQL:
create or replace package mike is
type dummy_record is varray (1) of dummy%rowtype;
PROCEDURE GENERATE_XML(i dummy_record, c CLOB);
FUNCTION SAYHELLO RETURN varchar2;
end mike;
show errors
create or replace package body mike is
PROCEDURE GENERATE_XML(i dummy_record,c CLOB)
AS LANGUAGE JAVA
NAME 'test.genXML(oracle.sql.ARRAY,oracle.sql.CLOB)';
FUNCTION SAYHELLO RETURN varchar2
AS LANGUAGE JAVA
NAME 'test.sayHello() return java.lang.String';
end mike;
show errors
DDL:
SQL> describe dummy
Name Null? Type
USERNAME VARCHAR2(20)
ID NUMBER
Test Script:
declare
m Mike.dummy_record := Mike.DUMMY_RECORD();
c CLOB;
begin
m.extend;
select xml into c from t_clob;
for rec in (select * from dummy)
LOOP
m(1) :=rec;
mike.generate_xml(m,c);
end loop;
end;
And finally, the output:
declare
ERROR at line 1:
ORA-21700: object does not exist or is marked for delete
ORA-06512: at "MMANGINO.MIKE", line 0
ORA-06512: at line 10
Sorry this post is so long, but I wanted it to be complete!
MikeThe first solution is to not do that in java in the first place.
DDL should be in script files which are applied to oracle outside of java.
Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation.
Maybe you are looking for
-
Ever since the latest update of the Adobe Flash Player, I think it came out this week. I can't seem to get it to work with Firefox, I have downloaded the installer, it installs successfully, then I check in Firefox to see if it works. It says that I
-
What is the use of production order without material?
Hi gurus, can anyone plz tell what is the use of production order without material? n steps involve to perform this task?
-
Lightroom 4 - Catalog problem?
I recently installed Lightroom 4.0 on my new Windows 7 Home Premiun SP1 (64 bit) computer and imported my Lightroom 3.6 catalog into a Lightroom 4 catalog. I have two problems which may or may not be related. First: While working in the Library, addi
-
I am developing a project on quiz. I have to show question and 4 options in one screen.also I want that the radio buttons(choice group)for the options should be selected by up down keys only.For using up down keys I have to extend canvas.if I extend
-
Making a subform appear when Digitally Signed
Hi, how would i get a hidden subform to appear when the pdf is digitally signed, what i need to appear is: form1.page1.subform6.SubmitForm.presence = "visable"; form1.page1.subform6.presence = "visable";