Super Class Examples of Exception
HELP!!!
I'm in need of assistance. I do not get Super classes and really how they work. Our book goes into such detail, it doesn't really give us a little example to work from for understanding. So here is a question: I need is Use Inheritance to create an exception class (ExceptionA) which is the super class, then subclasses ExceptionB class and ExceptionC class which both B and C classes inherit from A. We are suppose to write a program to catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC.
I can't grasp the concept of how to put these together. I'm not sure where the main method fits in all of these and does each have a try/catch that calls something from ExceptionA?
Ok..I'm just looking for help, yes an ANSWER to how to utilize (1) inheritance and then (2) to incorporate that into my homework. For example, I have an ExceptionA Class super, a subclass ExceptionB and a subclass ExceptionC. I'm really lost as to where do I put the main method. I have 3 methods, where do I put these and how do I call them. Does anyone have a little snippet of code that shows very basically a super class, a subclass that calls the superclass, and another subclass that calls the superclass and where the main fits in all of that. Below is all my code.
* Figure 13.17 Catching Exceptions with Superclasses
package Dialogs;
//superclass Exception
public class ExceptionA
//start of main method
public static void main( String args[] )
try
//call method one
one();
catch ( Exception exception )
exception.printStackTrace();
}//end of try/catch for main
} //end main method
}//end of ExceptionA
package Dialogs;
public class ExceptionsB extends ExceptionA
// exceptions back to main with one
public static void one() throws Exception
try
//call method two
two();
} // end try
catch ( Exception exception )
throw new Exception( "Exception in one", exception );
} // end try/catch for method one
} // end method one
}//end of class ExceptionsB
package Dialogs;
public class ExceptionC extends ExceptionA
// two method throws back to one
public static void two() throws Exception
try
//call method 3
three();
catch ( Exception exception )
throw new Exception( "Exception in two", exception );
} // end of try/catch two
} // end method 2
// throws Exception back to two
public static void three() throws Exception
throw new Exception( "Exception in three" );
} // end method 3
}
Similar Messages
-
Example of exception class for school
I know this may sound basic to some but, believe me, it's not to me! Does anybody have an example (I'll totally rewrite it to look different) of an exception class having an interface with at least 5 methods and 2 must throw the new exception? It would also have to implement the interface for each method and create a new main program that instantiates objects of the class while executing the methods that can. I'm taking a JAVA class and this problem is giving me big time grief! I'd really appreciate it and will help back if ever possible.
Soon-to-be-JAVA-flunkyRedboss wrote:
I know this may sound basic to some but, believe me, it's not to me! Does anybody have an example (I'll totally rewrite it to look different) of an exception class having an interface with at least 5 methods and 2 must throw the new exception? It would also have to implement the interface for each method and create a new main program that instantiates objects of the class while executing the methods that can. I'm taking a JAVA class and this problem is giving me big time grief! I'd really appreciate it and will help back if ever possible.
As hinted at you need to re-read your assignment. More likely you are to create two classes and an interface. One class will be your exception class. I'll give you the code for that because I'm such a generous guy.
public class MyException extends Exception{
}Then you'll create an interface that has 5 methods, two of which throw MyException. Then write a class that implements that interface.
Best of luck. If you have a specific problem implementing that then come back and ask but make sure to post your code when you do (use the code formatting tags, select the code you are posting in the message box and click the CODE button). No code. No help. -
Trying to use super class's methods from an anonymous inner class
Hi all,
I have one class with some methods, and a second class which inherits from the first. The second class contains a method which starts up a thread, which is an anonymous inner class. Inside this inner class, I want to call a method from my first class. How can I do this?
If I just call the method, it will use the second class's version of the method. However, if I use "super," it will try to find that method in the Thread class (it's own super class) and complain.
Any suggestions?
Code:
public class TopClass
public void doSomething(){
// do something
=============================
public class LowerClass extends TopClass
// overrides TopClass's doSomething.
public void doSomething(){
// do something
public void testThread(){
Thread t = new Thread(){
public void run(){
doSomething(); //fine
super.doSomething(); //WRONG: searches class Thread for doSomething...
t.start();
}Classes frequently call the un-overridden versions of methods from their superclasses. That's that the super keyword is for, if I'm not mistaken.You're not mistaken about the keyword, but you're not calling the superclass method from a subclass. Your anonymous inner class is not a subtype of TopLevel. It's a subtype of Thread.
Here it is no different, except that I happen to be in a thread at the time.It's vastly different, since you're attempting to call the method from an unrelated class; i.e., Thread.
I could also be in a button's action listener, for example. It seems natural to me that if I can do it in a method, I should be able to do it within an anonymous inner class which is inside a method.If you were in an button's action listener and needed to call a superclass' implementation of a method overridden in the button, I'd have the same questions about your design. It seems smelly to me.
~ -
I am trying to write a program that prints out the first 10 numbers of the fibonacci sequence. Unfortunately I am unsuccessful so far and getting nothing but errors. I am using jasmin and I have no idea what I am doing as this is my first time ever dealing with this language. I am not 100% sure but I am under the assumption is assembly but I only have luck doing a search by Java Virtual Machine. Can anybody help me with the following error. Any help will be much appreciated. Thanks in advance!!!
C:\Users\Chris\Desktop\jasmin\jasmin>java -cp . examples/Fibo
Exception in thread "main" java.lang.VerifyError: (class: examples/Fibo, method:
*main signature: ([Ljava/lang/String;)V) Expecting to find object/array on stack*
*Could not find the main class: examples/Fibo. Program will exit.*
Here is my written program
.class public examples/Fibo
.super java/lang/Object
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 5
.limit stack 10
getstatic java/lang/System/out Ljava/io/PrintStream;
astore_1
bipush 10
istore_2
iconst_0
dup
;invokevirtual java/io/PrintStream/println(I)V;
;invokestatic java/lang/String/valueOf(C)Ljava/lang/String;
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
istore_3
bipush 1
istore 4
L0:
iload 3
dup
iload 4
dup
;invokestatic java/lang/String/valueOf(C)Ljava/lang/String;
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
iadd
iload 4
istore 3
istore 4
iload_2
ifeq L1
iinc 2 -1
goto L0
L1:
return
.end method
OK guys I give up...I redid the program and its working better now.
*Note to moderators....if you please, you may delete this. Thanks!!!!!*
Edited by: chris52204 on Apr 12, 2009 3:21 PMcojogrizli wrote:
The structure of my project in Eclipse is src/project/files.java and in jar file is src/files.java bin/class.java Dati/ and META-INF/.That's wrong. You don't need the .java files in the jar (but you can have them, if you want, they are just not used by Java).
And each .class file must be in a directory that reflects its package. So in your example ProjectGUI.class must be in the directory projectRFID/ inside the .jar file. -
Error while calling a super class public method in the subclass constructor
Hi ,
I have code like this:
CLASS gacl_applog DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS:
create_new_a
IMPORTING pf_obj TYPE balobj_d
pf_subobj TYPE balsubobj
pf_extnumber TYPE string
EXPORTING pfx_log_hndl TYPE balloghndl
EXCEPTIONS error
ENDCLASS.
CLASS gacl_applog IMPLEMENTATION.
METHOD create_new_a.
DATA: ls_log TYPE bal_s_log.
Header aufsetzen
MOVE pf_extnumber TO ls_log-extnumber.
ls_log-object = pf_obj.
ls_log-subobject = pf_subobj.
ls_log-aluser = sy-uname.
ls_log-alprog = sy-repid.
ls_log-aldate = sy-datum.
ls_log-altime = sy-uzeit.
ls_log-aldate_del = ls_log-aldate + 1.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = pfx_log_hndl
EXCEPTIONS
OTHERS = 1.
IF ( sy-subrc NE 0 ).
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING error.
ENDIF.
ENDMETHOD.
CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
PUBLIC SECTION.
DATA: log_hndl TYPE balloghndl READ-ONLY
, t_log_hndl TYPE bal_t_logh READ-ONLY
METHODS: constructor
IMPORTING pf_obj TYPE balobj_d
pf_subobj TYPE balsubobj
pf_extnumber TYPE string
EXCEPTIONS error
, msg_add REDEFINITION
, display REDEFINITION
ENDCLASS.
CLASS gcl_applog_temp IMPLEMENTATION.
METHOD constructor.
CALL METHOD create_new_a
EXPORTING pf_obj = pf_obj
pf_subobj = pf_subobj
pf_extnumber = pf_extnumber
IMPORTING pfx_log_hndl = log_hndl.
IF ( sy-subrc NE 0 ).
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING error.
ENDIF.
ENDMETHOD.
A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass '
Can you please suggest how to change the code with out affecting the functioanlity.
Thank you ,
Lakshmi.Hi,
Call that method by instance of Subclass. OR
SUPER-->method.
Read very useful document
Constructors
Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
METHODS CONSTRUCTOR
IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
EXCEPTIONS.. <ei>.
and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
CLASS-METHODS CLASS_CONSTRUCTOR.
and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
Pls. reward if useful.... -
How to get the subclass from a super class( or interface)
hi,
I want to get subclass from a super class (or a interface), how to do that? the subclass of a interface means the class implementing the interface.
for example;
List ls;
I want to get the subclass of ls, i.e., LinkedList, Stack, Vector......
AbstractList al;
the subclass of al, i.e., ArrayList, Vector.......
thanks
AiwuList ls = new ArrayList();Since ls has been declared as a List we can only use List methods
with it. This is a good thing because we might later want to change
it to some other sort of List.
I want to get subclass from a super class (or a interface), how to do
that?The instance of the subclass declared above did not really come
from the super class. A class "knows nothing" about its
subclasses: many sub classes would not even exist at the time
the class was written. -
Not able to start the remote server - class not found exception
All,
I am quite new to RMI programming, although i am an experienced java programmer. I am facing a problem in starting the remote server program which i wrote for RMI. I am getting class not found exception for "stub" class eventhough the class is in the classpath.
Following is the error console:
cmd> java -classpath "D:\Eclipse_WorkSpaces\WS2\RMITests\classes" MyServerImplementation
GetNames error: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: MyServerImplementation_Stub
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: MyServerImplementation_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at MyServerImplementation.main(MyServerImplementation.java:21)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: MyServerImplementation_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: MyServerImplementation_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:434)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
... 12 morePLEASE ADVISE HOW TO RESOLVE THIS...
Following are my classes:
MyRemoteInterface.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface MyRemoteInterface extends Remote {
public String[] getNames() throws RemoteException;
public class MyServerImplementation extends UnicastRemoteObject implements
MyRemoteInterface {
public MyServerImplementation()throws RemoteException{
super();
public String[] getNames() throws RemoteException{
return new String[]{"Name1","Name2","Name3","Name4"};
public static void main(String args[]) {
try {
// Create an object of the HelloWorldServer class.
MyRemoteInterface obj = new MyServerImplementation();
// Bind this object instance to the name "HelloServer".
Naming.rebind("rmi://localhost:1985/GetNames", obj);
System.out.println("GetNames bound in registry");
catch (Exception e) {
System.out.println("GetNames error: " + e.getMessage());
e.printStackTrace();
public class MyRMIClient {
*@param args*
public static void main(String[] args) {
try {
MyRemoteInterface remObj = (MyRemoteInterface) Naming.lookup("rmi://localhost:1985/GetNames");
System.out.println("Names are "+remObj.getNames());
catch(Exception e) {
System.out.println("Problem encountered accessing remote object "+e);
}That's a remote exception coming from the registry. You need to learn to recognize remote exceptions and their source, it's a mjaor source of confusion in RMI.
In this case it's the registry that can't find the stub class.
The stub class needs to be in the CLASSPATH of (i) the Registry and (ii) the client as well. Ditto the remote interface; ditto any application classes it refers to, and so on until closure.
The easiest way to achieve (i) is to start it in the server's JVM, with LocateRegistry.createRegistry(). -
Class Not found Exception for invoking BPEL process through the Java code
Hi.
The JDeveloper IDE raise the Exception From the invoking the BPEL process through the java code .Class Not Found Exception (Locator,ID.......).What is process of importing these classes from API.In your code (.bpel file) import the library using the bpelx:exec tag. For example the adding the following entry in your .bpel file imports the com.oracle.bpel.client.util library.
<bpelx:exec import="com.oracle.bpel.client.util.*"/> -
B2B Java Callout Class not found exception
Hello B2B Gurus,
I am facing class not found exception, when trying to call a java code from B2B and below the configuration done from B2B side.
Could you please help me to identify that the configuration done suffice the requirement
1.Created a call out from
Adminstration-- Callout-- Create Callout -- XXJavaCallout(Name of the Java Callout)
Administration-- Callout Details -- Implementation Class -- XXClassFileName
Administration-- Callout Details -- Library Name -- XXJarFileName.jar
Administration-- Configuration -- Callout Directory -- xx/yy/zz (UNIX server that is accesible from B2B)
2.Partners--XX--Delivery Channel -- Select the channel where we need the call out -- Channel Attributes -- Transport Callout -- XXJavaCallout
3.Agreement--Callout -- XXJavaCallout
Place the jar file in xx/yy/zz UNIX location.
Please let me know if any steps I have missed for using the callout functionality.
Thanks,
Sunil
Edited by: Dathu Sunil on Mar 29, 2012 8:17 AMSunil,
Administration-- Callout Details -- Implementation Class -- XXClassFileNameMake sure that you are giving complete name of the class (without extension .class.). For an example if your class name is Sample and it is in package a.b.c then give class name as a.b.c.Sample
Administration-- Configuration -- Callout Directory -- xx/yy/zz (UNIX server that is accesible from B2B)This must be valid directory existing on machine where B2B is installed.
2.Partners--XX--Delivery Channel -- Select the channel where we need the call out -- Channel Attributes -- Transport Callout -- XXJavaCallout
3.Agreement--Callout -- XXJavaCalloutTransport Callout and Agreement Callouts are used for different purpose. Are you sure that you really need both in your case?
You may like to refer -
http://docs.oracle.com/cd/E17904_01/integration.1111/e10229/callouts.htm#CHDEFBDG
Regards,
Anuj -
Class Not Found Exception After Connecting From a JDeveloper
Hi,
I am following the tutorial on SOA and started to experience problems in deployments (all but the console, including em) after the connection to the remote weblogic (10.3.5) from JDeveloper. I would know if the connection modifies the WLS environment. Unfortunately I did not note the message before wiping the setup, but found many entries on Google referring to some ADF library. I followed the suggestion to apply the adf runtime to the WLS install but this not helped.
By the way, I would just understand if the remote connection from a JDeveloper adds some configuration which is then eventually not found in the target WLS.
Thanks
Fabio D'Alfonso
http://www.fabiodalfonso.comCan you check the log files of soa_server1, which are located in the <domain-home>/servers/<server-name>/logs.
There are probably some occurences of class not found exceptions.
When you are using the node manager to start your environment you have to make sure that StartScriptEnabled is set
to true in the nodemanager.properties file (located in the directory: <wl-home>/common/nodemanager
In the section "Starting the SOA environment" here - http://middlewaremagic.com/weblogic/?p=6040
an example is presented -
Class not Found Exception while running an EJB
I have created and published a EJB in Oracle 8i (in a particular
schema) by running the deployejb tool supplied. The ejb was
published successfully. On running the client program I get an
error saying that the mybeans's HomeHelper class cannot be
found. This error occurs when there is a lookup to the home
interface of the bean. The exception thrown says Reasons are
unknown. On checking the objects of type 'JAVA CLASS' I found
that the homeHelper class object had been created automatically
be the deploy process. What is the reason for the class not
found exception and what can I do to correct it. ?
The code for the beans is as given below :
Home Interface
package mituser ;
import javax.ejb.*;
import java.rmi.RemoteException;
public interface MITUserHome extends EJBHome {
public MITUser create()
throws CreateException, RemoteException;
Remote Interface
package mituser ;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface MITUser extends EJBObject {
public int validateUserName (String username)
throws java.sql.SQLException, RemoteException;
public int validatePassword (String username, String password)
throws java.sql.SQLException, RemoteException;
public String validateSearchAccess (String username, String
password)
throws java.sql.SQLException, RemoteException;
Bean
package mituserServer ;
import java.sql.*;
import java.rmi.RemoteException;
import javax.ejb.*;
public class MITUserBean implements SessionBean {
SessionContext ctx;
public void ejbCreate() throws CreateException,
RemoteException {
public void ejbActivate() {
public void ejbPassivate() {
public void ejbRemove() {
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
public int validateUserName (String username) throws
SQLException, RemoteException
int count = 0 ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select count(username) from
useraccountinfo where username = ?");
try {
ps.setString (1, username);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("no registered user with User
Name " + username);
count = rset.getShort(1) ;
return count ;
} finally {
ps.close();
public int validatePassword (String username, String password)
throws SQLException, RemoteException
int count = 0 ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select count(username) from
useraccountinfo where username = ? and password = ?");
try {
ps.setString (1, username);
ps.setString(2, password);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("Invalid Password ");
count = rset.getShort(1) ;
return count ;
} finally {
ps.close();
public String validateSearchAccess (String username, String
password) throws SQLException, RemoteException
String searchaccess = "" ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select searchprofileaccess from
useraccountinfo where username = ? and password = ?");
try {
ps.setString (1, username);
ps.setString(2, password);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("Access Denied for " +
username );
searchaccess = rset.getString(1) ;
return searchaccess ;
} finally {
ps.close();
Client program
import mituser.MITUser;
import mituser.MITUserHome;
import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class Client {
public static void main (String [] args) throws Exception {
int count = 0 ;
String access = "" ;
if (args.length != 4) {
System.out.println("usage: Client serviceURL objectName
user password");
System.exit(1);
String serviceURL = args [0];
String objectName = args [1];
String user = args [2];
String password = args [3];
Hashtable env = new Hashtable();
env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.SECURITY_AUTHENTICATION,
ServiceCtx.NON_SSL_LOGIN);
Context ic = new InitialContext(env);
MITUserHome home = (MITUserHome)ic.lookup (serviceURL +
objectName);
MITUser testBean = home.create ();
count = testBean.validateUserName("MITA");
if (count > 0 )
System.out.println ("Valid User");
else
System.out.println ("Invalid User");
count = testBean.validatePassword("MITA", "MITA");
if (count > 0 )
System.out.println ("Valid Password");
else
System.out.println ("Invalid Password");
access = testBean.validateSearchAccess("MITA", "MITA");
if ( access.equalsIgnoreCase("YES") )
System.out.println ("Search Access Available");
else
System.out.println ("Search Access Denied");
The Descriptor file
// MIT UserBean EJB deployment descriptor
SessionBean mituserServer.MITUserBean {
BeanHomeName = "test/mitUserJDBCBean";
RemoteInterfaceClassName = mituser.MITUser;
HomeInterfaceClassName = mituser.MITUserHome;
AllowedIdentities = {MIT};
SessionTimeout = 20;
StateManagementType = STATEFUL_SESSION;
RunAsMode = CLIENT_IDENTITY;
TransactionAttribute = TX_REQUIRED;
Batch File for deploying the ejb
@echo off
if (%ORACLE_HOME%)==() goto usage
if (%ORACLE_SERVICE%)==() goto usage
if (%JDK_CLASSPATH%)==() goto usage
@echo on
set CLASSPATH=.;%ORACLE_HOME%\lib\aurora_client.jar;%ORACLE_HOME%
\jdbc\lib\classes111.zip;%ORACLE_HOME%\sqlj\lib\translator.zip;%
ORACLE_HOME%\lib\vbjorb.jar;%ORACLE_HOME%\lib\vbjapp.jar;%
JDK_CLASSPATH%
javac -g mituser\MITUser.java
javac -g mituser\MITUserHome.java
javac -g mituserServer\MITUserBean.java
jar cf0 mituser.jar mituser\MITUser.class
mituser\MITUserHome.class mituserServer\MITUserBean.class
javac -g Client.java
call deployejb -republish -temp temp -u mit -p mit -s %
ORACLE_SERVICE% -descriptor mituser.ejb mituser.jar
@echo off
goto done
:usage
@echo -------------------------------------------------------
@echo Following are the requirements to run this script
@echo set ORACLE_HOME to installed Oracle home
@echo set ORACLE_SERVICE to the CORBA service name of
your databae
@echo for example sess_iiop://localhost:2481:ORCL
@echo set JDK_CLASSPATH to the full path of your JDK
classes.zip
@echo -------------------------------------------------------
:done
Batch file for running the cleint program
@echo off
if (%ORACLE_HOME%)==() goto usage
if (%ORACLE_SERVICE%)==() goto usage
if (%JDK_CLASSPATH%)==() goto usage
@echo on
set CLASSPATH=.;%ORACLE_HOME%\lib\aurora_client.jar;%ORACLE_HOME%
\jdbc\lib\classes111.zip;%ORACLE_HOME%\sqlj\lib\translator.zip;%
ORACLE_HOME%\lib\vbjorb.jar;%ORACLE_HOME%\lib\vbjapp.jar;%
JDK_CLASSPATH%;server_generated.jar
java Client %ORACLE_SERVICE% /test/mitUserJDBCBean mit mit
@echo off
goto done
:usage
@echo -------------------------------------------------------
@echo Following are the requirements to run this script
@echo set ORACLE_HOME to installed Oracle home
@echo set ORACLE_SERVICE to the CORBA service name of
your databae
@echo for example sess_iiop://localhost:2481:ORCL
@echo set JDK_CLASSPATH to the full path of your JDK
classes.zip
@echo -------------------------------------------------------
:done
I know this is not strictly to do with JDBC but there appears to
be no discussion forum for EJB
Hoping for a response soon as it us very URGENT
Thanks
Mita
nullI have created and published a EJB in Oracle 8i (in a particular
schema) by running the deployejb tool supplied. The ejb was
published successfully. On running the client program I get an
error saying that the mybeans's HomeHelper class cannot be
found. This error occurs when there is a lookup to the home
interface of the bean. The exception thrown says Reasons are
unknown. On checking the objects of type 'JAVA CLASS' I found
that the homeHelper class object had been created automatically
be the deploy process. What is the reason for the class not
found exception and what can I do to correct it. ?
The code for the beans is as given below :
Home Interface
package mituser ;
import javax.ejb.*;
import java.rmi.RemoteException;
public interface MITUserHome extends EJBHome {
public MITUser create()
throws CreateException, RemoteException;
Remote Interface
package mituser ;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface MITUser extends EJBObject {
public int validateUserName (String username)
throws java.sql.SQLException, RemoteException;
public int validatePassword (String username, String password)
throws java.sql.SQLException, RemoteException;
public String validateSearchAccess (String username, String
password)
throws java.sql.SQLException, RemoteException;
Bean
package mituserServer ;
import java.sql.*;
import java.rmi.RemoteException;
import javax.ejb.*;
public class MITUserBean implements SessionBean {
SessionContext ctx;
public void ejbCreate() throws CreateException,
RemoteException {
public void ejbActivate() {
public void ejbPassivate() {
public void ejbRemove() {
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
public int validateUserName (String username) throws
SQLException, RemoteException
int count = 0 ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select count(username) from
useraccountinfo where username = ?");
try {
ps.setString (1, username);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("no registered user with User
Name " + username);
count = rset.getShort(1) ;
return count ;
} finally {
ps.close();
public int validatePassword (String username, String password)
throws SQLException, RemoteException
int count = 0 ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select count(username) from
useraccountinfo where username = ? and password = ?");
try {
ps.setString (1, username);
ps.setString(2, password);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("Invalid Password ");
count = rset.getShort(1) ;
return count ;
} finally {
ps.close();
public String validateSearchAccess (String username, String
password) throws SQLException, RemoteException
String searchaccess = "" ;
Connection conn =
new oracle.jdbc.driver.OracleDriver().defaultConnection ();
PreparedStatement ps =
conn.prepareStatement ("select searchprofileaccess from
useraccountinfo where username = ? and password = ?");
try {
ps.setString (1, username);
ps.setString(2, password);
ResultSet rset = ps.executeQuery ();
if (!rset.next ())
throw new RemoteException ("Access Denied for " +
username );
searchaccess = rset.getString(1) ;
return searchaccess ;
} finally {
ps.close();
Client program
import mituser.MITUser;
import mituser.MITUserHome;
import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class Client {
public static void main (String [] args) throws Exception {
int count = 0 ;
String access = "" ;
if (args.length != 4) {
System.out.println("usage: Client serviceURL objectName
user password");
System.exit(1);
String serviceURL = args [0];
String objectName = args [1];
String user = args [2];
String password = args [3];
Hashtable env = new Hashtable();
env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.SECURITY_AUTHENTICATION,
ServiceCtx.NON_SSL_LOGIN);
Context ic = new InitialContext(env);
MITUserHome home = (MITUserHome)ic.lookup (serviceURL +
objectName);
MITUser testBean = home.create ();
count = testBean.validateUserName("MITA");
if (count > 0 )
System.out.println ("Valid User");
else
System.out.println ("Invalid User");
count = testBean.validatePassword("MITA", "MITA");
if (count > 0 )
System.out.println ("Valid Password");
else
System.out.println ("Invalid Password");
access = testBean.validateSearchAccess("MITA", "MITA");
if ( access.equalsIgnoreCase("YES") )
System.out.println ("Search Access Available");
else
System.out.println ("Search Access Denied");
The Descriptor file
// MIT UserBean EJB deployment descriptor
SessionBean mituserServer.MITUserBean {
BeanHomeName = "test/mitUserJDBCBean";
RemoteInterfaceClassName = mituser.MITUser;
HomeInterfaceClassName = mituser.MITUserHome;
AllowedIdentities = {MIT};
SessionTimeout = 20;
StateManagementType = STATEFUL_SESSION;
RunAsMode = CLIENT_IDENTITY;
TransactionAttribute = TX_REQUIRED;
Batch File for deploying the ejb
@echo off
if (%ORACLE_HOME%)==() goto usage
if (%ORACLE_SERVICE%)==() goto usage
if (%JDK_CLASSPATH%)==() goto usage
@echo on
set CLASSPATH=.;%ORACLE_HOME%\lib\aurora_client.jar;%ORACLE_HOME%
\jdbc\lib\classes111.zip;%ORACLE_HOME%\sqlj\lib\translator.zip;%
ORACLE_HOME%\lib\vbjorb.jar;%ORACLE_HOME%\lib\vbjapp.jar;%
JDK_CLASSPATH%
javac -g mituser\MITUser.java
javac -g mituser\MITUserHome.java
javac -g mituserServer\MITUserBean.java
jar cf0 mituser.jar mituser\MITUser.class
mituser\MITUserHome.class mituserServer\MITUserBean.class
javac -g Client.java
call deployejb -republish -temp temp -u mit -p mit -s %
ORACLE_SERVICE% -descriptor mituser.ejb mituser.jar
@echo off
goto done
:usage
@echo -------------------------------------------------------
@echo Following are the requirements to run this script
@echo set ORACLE_HOME to installed Oracle home
@echo set ORACLE_SERVICE to the CORBA service name of
your databae
@echo for example sess_iiop://localhost:2481:ORCL
@echo set JDK_CLASSPATH to the full path of your JDK
classes.zip
@echo -------------------------------------------------------
:done
Batch file for running the cleint program
@echo off
if (%ORACLE_HOME%)==() goto usage
if (%ORACLE_SERVICE%)==() goto usage
if (%JDK_CLASSPATH%)==() goto usage
@echo on
set CLASSPATH=.;%ORACLE_HOME%\lib\aurora_client.jar;%ORACLE_HOME%
\jdbc\lib\classes111.zip;%ORACLE_HOME%\sqlj\lib\translator.zip;%
ORACLE_HOME%\lib\vbjorb.jar;%ORACLE_HOME%\lib\vbjapp.jar;%
JDK_CLASSPATH%;server_generated.jar
java Client %ORACLE_SERVICE% /test/mitUserJDBCBean mit mit
@echo off
goto done
:usage
@echo -------------------------------------------------------
@echo Following are the requirements to run this script
@echo set ORACLE_HOME to installed Oracle home
@echo set ORACLE_SERVICE to the CORBA service name of
your databae
@echo for example sess_iiop://localhost:2481:ORCL
@echo set JDK_CLASSPATH to the full path of your JDK
classes.zip
@echo -------------------------------------------------------
:done
I know this is not strictly to do with JDBC but there appears to
be no discussion forum for EJB
Hoping for a response soon as it us very URGENT
Thanks
Mita
null -
Generic interface in abstract super class
hello java folks!
i have a weird problem with a generics implementation of an interface which is implemented in an abstract class.
if i extend from this abstract class and try to override the method i get this compiler error:
cannot directly invoke abstract method...
but in my abstract super class this method is not implemented as abstract!
do i have an error in my understanding how to work with generics or is this a bug in javac?
(note: the message is trown by the eclipse ide, but i think it has someting to do with javac...)
thanks for every hint!
greetings daniel
examples:
public interface MyInterface <T extends Object> {
public String testMe(T t);
public abstract class AbstractSuperClass<T extends AbstractSuperClass> implements MyInterface<T> {
public String testMe(T o) {
// do something with o...
// now we have a String str
return str;
public final class SubClass extends AbstractSuperClass<SubClass> {
@Override
public String testMe(SubClass o)
return super.testMe(o);
}Hi Wachtda,
Firstly, T extends Object is redundant as all classes implicitly extend the Object class.
Therefore :
public interface MyInterface <T> {
public String testMe(T t);
}Secondly, abstract classes may have both abstract and non-abstract instance methods. Also, two methods, one abstract and one non-abstract, must have a different signature.
The following example will give a compile error because the methods share the same signature :
abstract class Test {
public void sayHello() {
System.out.println("Hello");
abstract public void sayHello();
}Therefore, to make an interface method as abstract would simply block the possibility of implementing it.
BTW, you can do this :
abstract class Test {
public void sayHello() {
System.out.println("Hello");
abstract public void sayHello(String name);
}Finally, there's no bug in javac. -
Javah problem - super class could not be found !!
Hi all,
i have already posted this message but i didn't get enough help to solve my poor situation.
and this is my problem:
i got in my project (myProject) MyClass class.
i wrote in another java class ,in OtherClass.class ,jni function that use MyClass object as parameter to the jni interface, as follow:
private native int myFunction (MyClass obj); //function in OtherClass
when i write the javah command line :
javah -jni OtherClass (in order to create OtherClass.h)
i always get the following error:
A required super class myPackage.MyClass could not be found.
my qoustion is how can i let the javah command line to know about the existence of myPackage.MyClass and how can i create and .h file when i using other class instance as jni function parameter in other class??
Thanks Sendy.Lets define a few terms here.
Java can be a java virtual machine which is what runs when you type 'java' on the command line. It is also represented by the compiler which runs when you type 'javac'. And in your case it also is represented by 'javah'.
The class path defines where java finds classes that it needs.
In older versions of java you had to tell it where to find everything. It couldn't even find java.lang.String unless you told it were it was. Now days you have to tell it where to find stuff that you add (or where 3rd party libraries are.)
There are two ways to define the class path: a command line option and an environment variable.
A class path can, currently, have three types of things in it:
-A path to a zip file
-A path to a jar file
-A path
For example
-Path to zip file in windows: C:\mystuff\mylib\mystuff.zip
-Path to zip file in unix: /opt/system/projects/mystuff/mystuff.zip
-Path to jar file in windows: C:\mystuff\mylib\myjar.jar
-Path to jar file in unix: /opt/system/projects/mystuff/myjar.jar
-Path in windows: C:\mystuff\mylib
-Path in unix: /opt/system/projects/mystuff
Zip files aren't used as much anymore, but you should at least be aware of them.
Java uses the class path to look for classes which are stored in files. It does this by translating the class name into a file name. It uses packages as directory names and class names as file names. So in your case it would try to find a class called myPackage.MyClass in a file called myPackage\MyClass.class. It would try to find that in any zip files, jar files, in in any paths that you specified in the class path.
So java is trying to find myPackage\MyClass.class in your class path. It would try to find that in any zip files, jar files, in in any paths that you specified in the class path.
Right now your class path is probably just "." which means that if you do the following commands
cd C:\mystuff
javah -jni OtherClass
Then java is going to try to find myPackage.MyClass in the following file
.\myPackage\MyClass.class
That, because you 'cd' to C:\mystuff, translates to the following absolute path
C:\mystuff\myPackage\MyClass.class
So if java doesn't find that file then it is going to tell you that it can't find the file.
So where is your file? Let's say it is here.
C:\work\lib\myPackage\MyClass.class
So you must tell javah where the root is. Keep in mind that 'myPackage' must be part of the path. That is not optional. The root is the directory above 'myPackage'. So the root is
C:\work\lib
So now you have a path that is ready for your class path. So your javah command could look like this
javah -classpath ".;C:\work\lib" -jni OtherClass
Or using an environment variable
set CLASSPATH=.;C:\work\lib
javah -jni OtherClass
Keep in mind in the above that class path is a generic term and there can be other ways to define it. For example the Sun command "java" allows you to use "-classpath" or "-cp".
So does the above help? -
Is it possible to OVERLOAD a super-class method in a sub-class?
Hi all,
I have a query that
Is it possible to OVERLOAD a super-class method in a sub-class?
If it is possible, please give me an example.
Thanks,
HariHi,
Is the method int Display(int a){} overloading
the super-class's void Display() method? If
possible, please clarify this and how it would be
method overloading?
hanks,
Hari
Hi Hari,
Yes, it is possible. Look at this piece of code:
class Senior
void Display()
System.out.println("Super class method");
class Junior extends Senior
int Display(int a)
System.out.println("Subclass method: "+a);
return(a+10);
}> }
class example
public static void main(String args[])
Junior j = new Junior();
j.Display();
System.out.println("Subclass method
od "+j.Display(5));
Is this what you were asking? Hope this helped.Hi,
I guess you guys are confused here...
Overloading is achieved by methods in the same class...
Overriding is across a superclass subclass methds. -
Inherit protected attribute from a Super class
Hi All,
I am inheriting a standard class which has many instance protected attributes. how do i access the super classes protected attributes from the sub class. i.e i need the value present in the super class attribute to be used in a sub class method.
will i be able to get the value of an instance attribute??
Thanks in advance,
Arun.Hi marc,
I was also wondering as to how we can make use of the public attributes in the sub classes.as in, what the syntax we need to follow.
It'd be great if you could give a simple example with one protecetd attribute accessed in the subclass.
I've written a sample prog.
REPORT YA_TEST_OO.
CLASS s_abc DEFINITION
CLASS s_abc DEFINITION.
PRIVATE SECTION.
DATA: d_abc TYPE i.
ENDCLASS. "s_abc DEFINITION
CLASS sb_abc DEFINITION
CLASS sb_abc DEFINITION INHERITING FROM s_abc.
public SECTION.
DATA: sb_d_abc TYPE c." VALUE d_abc.
METHODS: m_abc.
ENDCLASS. "sb_abc DEFINITION
CLASS sb_abc IMPLEMENTATION
CLASS sb_abc IMPLEMENTATION.
METHOD m_abc.
sb_d_abc = d_abc + 1.
ENDMETHOD. "m_abc
ENDCLASS. "sb_abc IMPLEMENTATION
It doesn't work though.
Thanx,
Zid.
Maybe you are looking for
-
Qosmio F30 - no sound on Windows XP Pro
hello, first i have install Windows XP MCE, but few day ago i install Windows XP Profesional edition, and lose sound in my notebook. What was happen? How I can fix that? Someone say that is becouse Qosmio F30 cannot support Profesional edition. Truth
-
Syntax error in program "SAPLCRM_PRODUCT_PROPOSAL_TOOLS "
What happened? Error in the ABAP Application Program The current ABAP program "SAPLCRM_ORDER_OW" had to be terminated because it has come across a statement that unfortunately cannot be executed. The following syntax error occurre
-
Have to go out and then back into a text message to see reply
Is anyone having issues with the message app? when I am texting back and forth, I have to go out of the message and then go back in to see my friends reply? I hear the sound that they replied but don't see the message.. Anyone else having this issue
-
I need to know how much the screen of iphone 5s cost?
how much the screen of iphone 5s cost ?
-
Why do i have to RENDER a multi-clip in my timeline? but not reg clips?
don't recall that i've ever had to render a multiclip before in the timeline with no filters, etc... these are just standard multiclips. i'm in FCP 6 by the way.