Re: The problem to compile Java stored function in Oracle
On 05/31/2010 04:29 AM, Boris Poliakovsky wrote:
Could you please help to resolve the following problem ?
Text of Java Source:
create or replace and compile java source named "Hex2" as
import java.io.*;
import java.lang.*;
public class Hex2
{
public static int hexcase = 0; /* hex output format. 0 - lowercase; 1
- uppercase */
public static int chrsz = 8; /* bits per input character. 8 - ASCII;
16 - Unicode */
public static String hex_md5 (String s)
{
String rc = "z"+s;
try
{
rc = "z"+s;
}
catch (Exception e)
{
e.printStackTrace();
rc = "z"+s;
}
finally
{
return rc;
}
}
/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters>255 have their hi-byte silently
ignored.
*/
private static Object[] str2binl(String str)
{
Object[] bin;
int i = 0;
try
{
int mask = (1<< chrsz) - 1;
for(i = 0; i< str.length() * chrsz; i += chrsz)
bin[i>>5] |= (str.charAt(i / chrsz)& mask)<< (i%32);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
return bin;
}
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations
internally
* to work around bugs in some JS interpreters.
*/
private static int safe_add(byte x, byte y)
{
int rc0 = -1;
try
{
int lsw;
int msw;
lsw = (x& 0xFFFF) + (y& 0xFFFF);
msw = (x>> 16) + (y>> 16) + (lsw>> 16);
rc0 = (msw<< 16) | (lsw& 0xFFFF);
}
catch (Exception e)
{
e.printStackTrace();
rc0 = -1;
}
finally
{
return rc0;
}
}
}
The result of compilation in SQL*Plus:
SQL> @D:\app\Profiles\JAVA\Security\Hex2.jsp
77 /
Warning: Java created with compilation errors.
SQL> sho errors
Errors for JAVA SOURCE Hex2:
LINE/COL ERROR
--------------------------------------------------------------------------------
-----------------------------------------------------------------
0/0 Hex2:37: operator | cannot be applied to java.lang.Object,int
0/0 1 error
0/0 ^
0/0 bin[i>>5] |= (str.charAt(i / chrsz)& mask)<< (i%32);
SQL>
Oracle version:
Personal Oracle Database 10g Release 10.2.0.3.0 - Production
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
What is the problem ?
You have so many. The error message says that you cannot OR (the pipe
operator '|') and 'Object' to an 'int' - you did see that much, right? If
not, there's not much hope.
What OR operator? The one in the OR-EQUALS, '|=', of course. What's the left
operand? 'bin[i>>5]', which is an 'Object'. What's the right operand? An
'int' expression '(str.charAt(i / chrsz)& mask)<< (i%32)'. What were you
thinking would happen?
You can't OR an 'Object' with an 'int'.
You also never assigned 'bin' to any actual array. You have an uninitialized
variable there.
You also seem to think that 'rc = "z"+s;' can throw an exception. WTF?
And how does repeated concatenation of 's' to "z" do anything?
And just where does standard-error go from a stored procedure?
Why are your static member variables declared 'public'?
And have you ever heard of indentation? Hm?
--
Lew