Problem Using Multiple With Statements

I'm having a problem using multiple WITH statements. Oracle seems to be expecting a SELECT statement after the first one. I need two in order to reference stuff from the second one in another query.
Here's my code:
<code>
WITH calculate_terms AS (SELECT robinst_current_term_code,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
END first_term,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
END second_term
FROM robinst
WHERE robinst_aidy_code = :aidy)
/*Use terms from calculate_terms to generate attendance periods*/
WITH gen_attn_terms AS
SELECT
CASE
WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
END first_attn_period,
CASE
WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
END second_attn_period
FROM calculate_terms
SELECT *
FROM gen_attn_terms
<code>
I get ORA-00928: missing SELECT keyword error. What could be the problem?

You can just separate them with a comma:
WITH calculate_terms AS (SELECT robinst_current_term_code,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
END first_term,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
END second_term
FROM robinst
WHERE robinst_aidy_code = :aidy),
/*Use terms from calculate_terms to generate attendance periods*/
gen_attn_terms AS
SELECT
CASE
WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
END first_attn_period,
CASE
WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
END second_attn_period
FROM calculate_terms
)Not tested because there are no scripts.

Similar Messages

  • Problem using multiple contexts in same thread

    Hello,
    I am having problem using multiple contexts in the same thread. Here is the scenario:
    front-end is calling a ejb1 with a user1 and password. Ejb1 is then calling ejb2
    using user2 and password. I am getting security exception when calling ejb2 with
    the message user1 is not authorized. Looking at the documentation, context 2 should
    be pushed on stack on top of context 1 and context 2 should then be used until
    context.close() is called. It looks like this is not the case in this scenario?
    Regards,
    Jeba Bhaskaran

    I have the GTX670. So pretty much the same.
    When I go to  Edit>Preferences>Playback I see:
    When I select the monitor I am not currently using for Premiere Pro, the Program Monitor shows up full size at 1920X1080 in that monitor.
    While that may not help you, at least you know a similar card can do the job and you know that it should work.. What happens if you drop down to two monitors? Will it work then?
    Also, have you performed the hack that allows Premiere Pro to use the card since that card is not in the file? I have no idea if that is relevant at all, by the way. It is just an attempt at getting our systems to work the same way.

  • Problem using Toplink with JUnit

    Hi,
    I have a problem using Toplink with JUnit. Method under test is very simple: it use a static EntityManager object to open a transaction and persists data to db. When I invoke the method from a test method, it gives me the exception:
    java.lang.AssertionError
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:248)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:232)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:216)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initialize(JavaSECMPInitializer.java:239)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initializeFromMain(JavaSECMPInitializer.java:278)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.getJavaSECMPInitializer(JavaSECMPInitializer.java:81)
         at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:119)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
         at it.valerio.electromanager.model.EntityFacade.<clinit>(EntityFacade.java:12)
         at it.valerio.electromanager.business.ClienteBiz.insertIntoDatabase(ClienteBiz.java:36)
         at it.valerio.electromanager.test.model.ClienteTest.insertDBTest(ClienteTest.java:30)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
         at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
         at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
         at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Where is the problem???
    Regards,
    Valerio

    EntityFacade class is very simple and it uses a static EntityManager object. Here the code:
    public class EntityFacade {
         private static EntityManager em = Persistence.createEntityManagerFactory("ElectroManager").createEntityManager();
         private static Logger logger=Logger.getLogger(EntityFacade.class);
         public static void insertCliente(Cliente c)
              logger.debug("Inserisco cliente nel db: " + c);
              em.getTransaction().begin();
              c.setId(getNextIdForTable("Cliente"));
              em.persist(c);
              em.getTransaction().commit();
    If I call the method from inside a main it works well, so I think the problem is not the classpath neither the URL in the persistence.xml. However the URL is:
    <property name="toplink.jdbc.url" value="jdbc:derby:c:/programmi/ElectroManager/db/electroManager"/>
    I use the latest build version of TopLink.
    Thanks.

  • Any Problems using SSL with Safari and the move with Internet explorer to require only TLS encryption.

    Any Problems using SSL with Safari and the move with Internet explorer to require only TLS encryption.

    Hi .
    Apple no longer supports Safari for Windows if that's what you are asking >  Apple apparently kills Windows PC support in Safari 6.0
    Microsoft has not written IE for Safari for many years.

  • Problem using ViewObject with bc4j:table

    Hello !!
    This is the query of my ViewObject:
    select * from speiseplan order by jahr desc, kw desc;
    and everything works fine in the BC4J tester:
    jahr kw
    2003 52
    2003 7
    2003 3
    2002 51
    But in my uix page the rows are not correctly sorted:
    jahr kw
    2003 3
    2003 7
    2003 52
    2002 51
    What's going wrong here?
    Thanks for your help.
    Regards,
    Mareike

    Duplicate post.
    Original problem using ViewObject with <bc4j:table>

  • Problems using iCloud with Mountain Lion on iMac8,1

    problems using iCloud with Mountain Lion on iMac8,1 - about 5J old - iMac gets slower and slower - total free memory is used in some minutes - no more reaction on input

    Download > http://codykrieger.com/gfxCardStatus Open it and select Integrated Only. It's a bug with NVIDIA graphic cards

  • BC4J Problem using multiple EntityObjects in a single ViewObject

    Hi,
    I have found a bug while using multiple EntityObjects in a single ViewObject.
    Considere the following example:
    Table A:
    A_ID
    Table B:
    B_ID
    A_ID (FK) NULLABLE
    TABLE C:
    C_ID
    B_ID (FK) NULLABLE
    For each table there is a corresponding EntityObject : AEntity, BEntity and CEntity.
    Now building a ViewObject based on CEntity, BEntity and AEntity, where AEntity and BEntity are referenced via their corresponding associtaions, the following problem occurs:
    1. As long as both IDs are not NULL everything works fine, but when I set the B_ID attribute of CEntity to NULL I receive a NullPointerException with the detail "null".
    2. If the attribute A_ID of BEntity is NULL the values based on AEntity are not updated at all (they keep the value they had for the last row).
    Any information or feedback on this issue would be very welcome!
    Regards
    Frank

    Here's a sample code that works for a
    LineItem->OrdView->CustomerView case,
      public void setOrdId(Number value)
        //set the boolean if there's a current order.
        boolean hasOrd = (getEntity(1) != null);
        setAttributeInternal(ORDID, value);
        //after the OrdID is set, check if there's a valid Ord Entity in this row.
        if (hasOrd && getEntity(1) == null)
          //if not, then set the Customer Entity to null as well.
          super.setEntity(2, null);
          LinesViewImpl vo = (LinesViewImpl)getViewObject();
          //And force a RowUpdated event for "customer-entity-usage-attributes".
          vo.notifyRowUpdated(findRowSetForRow(null), new oracle.jbo.Row[] {this}, new int[]{6,7});
      } Note that in the above, you have to "override" notifyRowUpdated method in the ViewObjectImpl subclass, so that it's available to the LineViewRowImpl subclass. You can do this
    globally by creating a custom subclass of ViewObjectImpl that all the VOs in your application "extends".

  • Best way to ensure combinations from the ValidationSet parameter attribute are processed correctly in PowerShell without using multiple IF statements?

    I have an advanced function I have been working on that looks something like this:
    Function Do-Something
    [cmdletbinding()]
    Param
    [Parameter(Mandatory=$true,
    [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
    [string[]]$Param1,
    [Parameter(Mandatory=$true,
    [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
    [string[]]$Param2,
    [Parameter(Mandatory=$true,
    [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
    [string[]]$Param3
    Begin {}
    Process
    My question is, how do I get the values such as "Yes", "Y", "No", and "N" that's located in the [ValidateSet()] validation attribute processed correctly without having to use multiple "If" and "ElseIf"
    statements. 
    For instance, I want to avoid the following, because I know there is a faster and more efficient way (less typing) to do it:
    If ($param1 -match "Yes" -or "Y" -and $param2 -match "Yes" -or "Y" -and $param3 -match "Yes" -or "Y")
    #Do something here
    ElseIf  ($param1 -match "No" -or "N" -and $param2 -match "Yes" -or "Y" -and $param3 -match "Yes" -or "Y")
    #Do something
    I was reading that splatting may help me here, but I am new to the splatting technique and need some help with this one.
    I appreciate any help that anyone can offer. 
    Thanks

    Is this what you are trying to ask how to do?  Your posted script is written incorrectly and will not work at all. 
    Function Do-Something{
    [cmdletbinding()]
    Param (
    [Parameter(Mandatory=$true)]
    [ValidateSet('Yes','No','Y','N')]
    [string]$p1,
    [Parameter(Mandatory=$true)]
    [ValidateSet('Yes','No','Y','N')]
    [string]$p2
    Begin{
    Process{
    # parse the strings to booleans
    $p1a=if($p1 -match 'Yes|Y'){$true}else{$false}
    $p2a=if($p2 -match 'Yes|Y'){$true}else{$false}
    if($p1a){Write-Host 'P1 is good' -ForegroundColor green}
    if($p2a){Write-Host 'P2 is good' -ForegroundColor green}
    if($p1a -and $p2a){
    Write-Host 'All conditions met' -ForegroundColor green
    }else{
    Write-Host 'Conditions not met' -ForegroundColor red
    PS C:\scripts> Do-Something Y n
    P1 is good
    Conditions not met
    PS C:\scripts> Do-Something n n
    Conditions not met
    PS C:\scripts> Do-Something y y
    P1 is good
    P2 is good
    All conditions met
    This handles case and creates a tracking Boolean fo reach parameter so you can just build simple logic.
    ¯\_(ツ)_/¯

  • Are there any problems using transitions with a layered menu

    I am creating a DVD using layered Photoshop files for the menus. I know there are many issues when doing this.
    I have 2 questions.
    Will creating a 3 state button (normal, rollover, select) cause more problems than a 2 state button?
    Can I use the menu trasitions with a layered Photoshop menu?
    Thanks

    I don't know of many "issues". In fact i think using photoshop files is a standard practice.
    The only issue i can see from having a 3 state button is using an overlay in the normal state might create some distortion in your button, but other than that there can be some great advantages to using all three states like an overlay mask.
    Yes you can use the transitions. One of the best ways to find out is to give it a try.

  • Use Multiple Insert Statements in Prepared Statements

    Hi Friends
    i am stuck in a problem for which i need your help.i will brief you about the issue below.
    I am having Multiple Insert Statements which i need to execute to put the data in the database.i have a doubt about the use of the executeUpdate() function in the statement interface. sample code is as below.
    stmt = conn.prepareStatement("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, ) VALUES(PID, 2, '123123123', '123', '66', 1, 1 );");
    int n =stmt.executeUpdate();
    Now the problem is how do i insert multiple Insert statements using the conn.prepareStatement().should i do like
    stmt = conn.prepareStatement("")
    int n =stmt.executeUpdate();
    stmt = conn.prepareStatement("")
    int n =stmt.executeUpdate();
    stmt = conn.prepareStatement("")
    int n =stmt.executeUpdate(); ..................................
    should i use the same steps to execute each individual query and then use executeUpdate().
    Please let me know the correct procedure to be followed to execute these tasks.waiting for a positive reply from your side.
    Thanks & Regards
    Vikram K

    Hi
    Thanks a lot once agin for the reply.
    I think i have figured out the solution. I am using SQL statements in the Prepared statements(""). But now i have dropped the idea of using the prepared statement and decided to use the simple Statement instead.
    what i have done is as below.
    conn = ConnectionFactory.getInstance().getConnection();
    stmt = conn.createStatement();
    stmt.executeUpdate("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, heightMeasurementType, weightMeasurementType ) VALUES(PID, '1', '1', '0', '1', 'Mr', CONCAT('Jason ', PID), 'R', 'Mawdsley', '123', '66', 1, 1 );");
    stmt.executeUpdate("INSERT into Cp () Values ()");
    stmt.executeUpdate("INSERT into gp () Values ()");
    stmt.executeUpdate("INSERT into jk () Values ()");
    I think this makes sense to use the Statement and execute all the queries in one shot rather than using PS.
    thanks a lot for your help.
    Regards
    Vikram K

  • Problems using SessionBroker with WebSphere

    Hello!
    I have some problems using a SessionBroker with WebSphere 5.1. In our project we use Entity Beans with BMP and everything works fine as long as we use a ServerSession. But when I use a SessionBroker instead, even though it wraps only one session, I get a NullPointerException every time I try to access an Entity Bean. See the stack trace below.
    It is important for our project to use multiple sessions and relationships between objects coming from different sessions in the next stage of the development
    By the way: The server session uses the appropriate external transaction controller, i.e. oracle.toplink.jts.was.JTSExternalTransactionController_5_1
    Thanks in advance for your help!
    Thomas
    java.lang.NullPointerException
         at oracle.toplink.ejb.EJBDataStore.store(EJBDataStore.java:572)
         at oracle.toplink.ejb.bmp.BMPEntityBase.ejbStore(BMPEntityBase.java:115)
         at com.ibm.ejs.container.BeanManagedBeanO.store(BeanManagedBeanO.java:233)
         at com.ibm.ejs.container.EntityBeanO.beforeCompletion(EntityBeanO.java:1062)
         at com.ibm.ejs.container.ContainerTx.beforeCompletion(ContainerTx.java:542)
         at com.ibm.ejs.util.tran.SyncDriver.beforeCompletion(SyncDriver.java:279)
         at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:110)
         at com.ibm.ws.Transaction.JTA.TransactionImpl.internalPrepare(TransactionImpl.java:1213)
         at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:962)
         at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:150)
         at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:182)
         at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:712)
         at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:167)
         at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:565)
         at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:3038)
         at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:2916)

    Unfortunately there is no way to do this in 9.0.4. This has been fixed in the 10.1.3 preview release, in 9.0.4 you will need to create your session broker in code to work around the problem.
    If you require sessions.xml support for this in 9.0.4, please contact Oracle support.

  • Problems Using Viber with new iPhone 4S

    When I try and use VIber with my new iPhone is says push notifications are not enabled, even though I've enabled them. I've also tried deleting and reinstalling viber several times, along with restarting the phone. Is anyone else having the same problem and does anyone have any suggestions of something else I could do?

    Hi,
    This is a member of Viber's development team.
    @libbyfromchristchurch - Please check: http://helpme.viber.com/index.php?/Knowledgebase/Article/View/38/0/push-notifica tions-for-iphone---how-to-enable
    @quyenfromseattle - This is a known issue which will be resolved shortly. Make sure that you stay current with our version updates.
    It may help to change 'banners' to 'alerts' on Viber's Push Notification settings as a temporary workaround.
    Thank you for your patience!

  • Problem using ipod with itunes 5.0.1

    Could anyone help me?? I'm having serious problems using my ipod mini with my "just downloaded" itunes 5.0.1.
    it says that my comunication software with ipod is not correctly installed and that i have to reinstall itunes again. i did it the problem is always there. what can i do?? can someone help me??

    Man, it seems that iTunes 5.whatever has gotten us all a little hot under the collar. I'm back up and running...this is what I did...I hope it helps some of you out.
    1) created a new folder in MyMusic and copied everything from my iTunes library to the new folder. I then tested a few songs to make sure they still played (you never know)
    2) I deleted iTunes using the control panel selection Add/Delete programs. I emptied the recycle gin and then did a search to see that iTunes was no longer there.
    3) I went to filehippo.com to download iTunes 4.8 (my original disks are packed (Thank you to poster Allison for the filehippo.com suggestion).
    4) I copied all my songs back into iTunes from where I had stored them in the new folder I created in MyMusic)
    5) I connected the iPod Mini and opened iTunes and darn if it STILL didn't recognize the iPod
    6) I did a restore on the iPod
    7) I reconnected the iPod and had to reregister it and Voila! it worked again!!!!
    Whatever the new features were in ver. 5.01, they were NOT worth the hassle I've experienced over the past two weeks. I'll stick with version 4.8 for awhile.

  • Problem using SmartCard with 2 Certificates stored and SunPKCS11

    Hi,
    I'm trying to access one SmartCard token in Java 1.5 using SunPKCS11 provider for crypt, decrypt and digital signature operations.
    I have 2 certificates stored on Token:
    - CertA;
    - CertB.
    There are also 2 PIN:
    - PIN1;
    - PIN2.
    I use:
    - PIN1 for logging into the token;
    - PIN1 for operation involving CertA;
    - PIN2 for operation involving CertB;
    There is no problem to logging into the token using Java and, without any troubles, I can read certificates and key from the
    cryptographic card.
    There is no problem using CertA for all my operation, but every attempt of using Private Key of CertB (for the same operations) returns with an Exception:
    java.security.ProviderException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DEVICE_ERROR
    Here there's an extract of my source code.
    public void loginToken() {
    Provider UserProvider = new sun.security.pkcs11.SunPKCS11(C:\\pkcs11.cfg);
    Security.addProvider(UserProvider);
    try {
    KeyStore ks = null;
    X509Certificate UserCert = null;
    PrivateKey UserCertPrivKey = null;
    PublicKey UserCertPubKey = null;
    //PIN
    char PIN1[] = "11111".toCharArray();
    char PIN2[] = "22222".toCharArray();
    //logging into token
    ks = KeyStore.getInstance("PKCS11", UserProvider);
    ks.load(null, PIN1);
    //enumeration alias
    String alias = "";
    Enumeration e = ks.aliases();
    while (e.hasMoreElements()) {
    alias = (String) e.nextElement();
    //Certificate
    UserCert = (X509Certificate) ks.getCertificate(alias);
    //PublicKey
    UserCertPubKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
    if (alias.compareToIgnoreCase("Cert1") == 0) {
         //PrivateKey reference     
    UserCertPrivKey = (PrivateKey) ks.getKey(alias, PIN1);
    } else if (alias.compareToIgnoreCase("Cert2") == 0) {
    //PrivateKey reference
    UserCertPrivKey = (PrivateKey) ks.getKey(alias, PIN2);
    } else {
    System.out.println("ALIAS UNKNOW");
    System.exit(1);
    //Signature Test
    if (!MakeSignature(UserCertPrivKey, UserProvider))
    System.out.println(" *** SIGNATURE OK *** ");
    else
    System.out.println(" *** SIGNATURE KO *** ");
    catch (Exception ex) {
    System.out.println("ERROR: " + ex);
    public boolean MakeSign(PrivateKey PrivKey, Provider p) {
    try {
    //File I/O
    FileInputStream txtfis = new FileInputStream("C:\\Test.txt");
    FileOutputStream sigfos = new FileOutputStream("C:\\Test_Signature.txt");
    //Signature Obj init
    Signature dsa = Signature.getInstance("SHA1withRSA", p.getName());
    dsa.initSign(PrivKey);
    //Update data
    BufferedInputStream bufin = new BufferedInputStream(txtfis);
    byte[] buffer = new byte[1024];
    int len;
    while (bufin.available() != 0) {
    len = bufin.read(buffer);
    dsa.update(buffer, 0, len);
    bufin.close();
    //Make signature
    byte[] realSig = dsa.sign();
    //save signature on file
    sigfos.write(realSig);
    sigfos.close();
    return true;
    catch (Exception ex) {
    System.out.println("ERROR: " + ex);
    return false;
    Any help would be grateful...
    Thanks in advance.
    P.S. Sorry for my English

    This is the same my initial problem.
    I resolved it using IAIK-PKCS#11Wrapper (it is FREE) insted of sun.security.pkcs11.SunPKCS11.
    You can find it here:
    http://jce.iaik.tugraz.at/sic/products/core_crypto_toolkits/pkcs_11_wrapper
    Here an exemple of code.
    The main class:
    import iaik.pkcs.pkcs11.Module;
    import iaik.pkcs.pkcs11.DefaultInitializeArgs;
    import java.util.Hashtable;
    import iaik.pkcs.pkcs11.Token;
    import iaik.pkcs.pkcs11.Slot;
    import iaik.pkcs.pkcs11.Session;
    import iaik.pkcs.pkcs11.objects.RSAPrivateKey;
    import java.util.Vector;
    import iaik.pkcs.pkcs11.objects.PrivateKey;
    import iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate;
    import java.util.Enumeration;
    import iaik.pkcs.pkcs11.objects.Key;
    import java.security.cert.CertificateFactory;
    import java.io.ByteArrayInputStream;
    import iaik.pkcs.pkcs11.Mechanism;
    import java.security.Security;
    import org.bouncycastle.jce.provider.BouncyCastleProvider;
    import java.io.File;
    import java.io.FileInputStream;
    import org.bouncycastle.cms.CMSSignedDataGenerator;
    import org.bouncycastle.cms.CMSProcessableByteArray;
    import java.util.ArrayList;
    import java.security.cert.CertStore;
    import java.security.cert.CollectionCertStoreParameters;
    import org.bouncycastle.cms.CMSSignedData;
    import java.io.FileOutputStream;
    import java.security.cert.X509Certificate;
    import iaik.pkcs.pkcs11.TokenInfo;
    import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
    public class MakeSignature {
      public static void main(String[] args) {
         String USER_PIN = "12345678";
         String DLL_NAME = "C:\\windows\\system32\\dll_P11_name.dll";
         String OBJ_LABEL1 = "CNS0"; //this is the label of my 1th cert
         String OBJ_LABEL2 = "CNS1"; //this is the label of my 2th cert
         String INPUT_FILE = "C:\\Temp\\test.txt";
         String OUTPUT_FILE = "C:\\Temp\\test.p7m";
        try {
           // ********** INITIALIZE PKCS#11 MODULE WITH DEFAULT PARAMETERS **********
          Module pkcs11Module = Module.getInstance(DLL_NAME);
          pkcs11Module.initialize(new DefaultInitializeArgs());
           // ********** SELECT TOKEN **********
          Slot[] slotsWithToken = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
          Token[] tokens = new Token[slotsWithToken.length];
          Hashtable tokenIDtoToken = new Hashtable(tokens.length);
          long tokenID = -1;
          Token tokenUsed = null;
          //enum readers
          for (int i = 0; i < slotsWithToken.length; i++) {
            tokens[i] = slotsWithToken.getToken();
    tokenID = tokens[i].getTokenID();
    tokenIDtoToken.put(new Long(tokenID), tokens[i]);
    System.out.println("Active tokens:");
    System.out.println("Token ID: " + tokenID);
    if (tokens.length == 0) { //No SC found
    System.out.println("No SC presents");
    else {
    System.out.println("Using token: " + tokens[0].getTokenID());
    tokenUsed = tokens[0];
         //Note: if you have more reader and more SC inserted, you have to write
         //here the code for select the right token
         // ********** OPEN SESSION VS THE TOKEN AND IF REQUIRED SUBMIT PIN **********
    TokenInfo tokenInfo = tokenUsed.getTokenInfo();
    Session session = tokenUsed.openSession(Token.SessionType.SERIAL_SESSION, false, null, null);
    if (tokenInfo.isLoginRequired()) {
    session.login(Session.UserType.USER, USER_PIN.toCharArray());
         // ********** SET SEARCH TEMPLATE FOR THE P11 OBJECT **********
    RSAPrivateKey privateSignatureKeyTemplate = new RSAPrivateKey();
    privateSignatureKeyTemplate.getSign().setBooleanValue(Boolean.TRUE);
    privateSignatureKeyTemplate.getLabel().setCharArrayValue(OBJ_LABEL2.toCharArray());
         // ********** SEARCH P11 OBJECT USING TEMPLATE **********
    Vector keyList = new Vector(4);
    session.findObjectsInit(privateSignatureKeyTemplate);
    Object[] matchingKeys;
    while ( (matchingKeys = session.findObjects(1)).length > 0) {
    keyList.addElement(matchingKeys[0]);
    session.findObjectsFinal();
         //Try to find the corresponding certificates for the signature keys
    Hashtable keyToCertificateTable = new Hashtable(4);
    Enumeration keyListEnumeration = keyList.elements();
    while (keyListEnumeration.hasMoreElements()) {
    PrivateKey signatureKey = (PrivateKey) keyListEnumeration.nextElement();
    byte[] keyID = signatureKey.getId().getByteArrayValue();
    X509PublicKeyCertificate certificateTemplate = new X509PublicKeyCertificate();
    certificateTemplate.getId().setByteArrayValue(keyID);
    session.findObjectsInit(certificateTemplate);
    Object[] correspondingCertificates = session.findObjects(1);
    if (correspondingCertificates.length > 0) {
    keyToCertificateTable.put(signatureKey, correspondingCertificates[0]);
    session.findObjectsFinal();
         //There are three cases now: 1 no obj found; 2 found only one obj, 3 found more obj
    Key selectedKey = null;
    X509PublicKeyCertificate correspondingCertificate = null;
    //no object found for template
    if (keyList.size() == 0) {
    System.out.println("No object found for template");
    throw new Exception("No object found for template");
    //Founf only one object
    else if (keyList.size() == 1) {
    selectedKey = (Key) keyList.elementAt(0);
    // create a IAIK JCE certificate from the PKCS11 certificate
              correspondingCertificate = (X509PublicKeyCertificate)keyToCertificateTable.get(selectedKey);
    System.out.println("One object Found");
    //Found more object ... user can select one
    else {
         System.out.println("Many obj found!!!");
    //write here the code for select the right object
         // ********** GET THE OBJECT **********
    RSAPrivateKey signerPriKey = (RSAPrivateKey) selectedKey;
    java.security.cert.CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    byte[] derEncodedCertificate = correspondingCertificate.getValue().getByteArrayValue();
    //Cast to java.security.cert.X509Certificate
    java.security.cert.X509Certificate signerCert = (java.security.cert.X509Certificate) certificateFactory.
    generateCertificate(new ByteArrayInputStream(derEncodedCertificate));
         // ********** SIGNATURE OPERATION **********
    //Add BouncyCastle as provider
    Security.addProvider(new BouncyCastleProvider());
    //initialize signature operation
    session.signInit(Mechanism.RSA_PKCS, (PrivateKey) signerPriKey);
    //get input data
    File src = new File(INPUT_FILE);
    int sizecontent = ( (int) src.length());
    byte[] contentData = new byte[sizecontent];
    FileInputStream freader = new FileInputStream(src);
    freader.read(contentData, 0, sizecontent);
    freader.close();
         //calculate digest of the input data
    byte[] toEncrypt = buildBits(contentData); //I've already posted the code for this function
    //make signature
    byte[] signature = session.sign(toEncrypt);
         // ********** MAKE P7 WELL FORMAT DOCUMENT **********
    //CMSSignedDataGenerator fact = new CMSSignedDataGenerator();
    Signature2CMSSignedData fact = new Signature2CMSSignedData();
    CMSProcessableByteArray content = new CMSProcessableByteArray(contentData);
    //Creation of BC CertStore
    ArrayList certList = new ArrayList();
    certList.add(signerCert);
    CertStore certs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC");
    //Signature Alg
    String algorithm = CMSSignedDataGenerator.DIGEST_SHA1;
    //add element to P7
    fact.addSignature(signature, signerCert, algorithm);
    fact.addCertificatesAndCRLs(certs);
    //generate enveloped using Bouncycastle provider
         CMSSignedData envdata = fact.generate(PKCSObjectIdentifiers.data.getId(), content, true);
    byte[] enveloped = envdata.getEncoded();
    //Write P7 file
    FileOutputStream efos = new FileOutputStream(OUTPUT_FILE);
    efos.write(enveloped);
    efos.close();
    // ********** END **********
    session.closeSession();
    pkcs11Module.finalize(null);
    catch (Exception ex) {
    ex.printStackTrace();
    }Main class uses buildBits function (already posted in this topic) and Signature2CMSSignedData class.import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.security.cert.CertStore;
    import java.security.cert.X509CRL;
    import java.security.cert.X509Certificate;
    import org.bouncycastle.asn1.ASN1EncodableVector;
    import org.bouncycastle.asn1.ASN1InputStream;
    import org.bouncycastle.asn1.ASN1OctetString;
    import org.bouncycastle.asn1.ASN1Sequence;
    import org.bouncycastle.asn1.ASN1Set;
    import org.bouncycastle.asn1.BERConstructedOctetString;
    import org.bouncycastle.asn1.DEREncodable;
    import org.bouncycastle.asn1.DERNull;
    import org.bouncycastle.asn1.DERObject;
    import org.bouncycastle.asn1.DERObjectIdentifier;
    import org.bouncycastle.asn1.DEROctetString;
    import org.bouncycastle.asn1.DERSet;
    import org.bouncycastle.asn1.cms.ContentInfo;
    import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
    import org.bouncycastle.asn1.cms.SignedData;
    import org.bouncycastle.asn1.cms.SignerIdentifier;
    import org.bouncycastle.asn1.cms.SignerInfo;
    import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
    import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
    import org.bouncycastle.asn1.x509.CertificateList;
    import org.bouncycastle.asn1.x509.TBSCertificateStructure;
    import org.bouncycastle.asn1.x509.X509CertificateStructure;
    import org.bouncycastle.cms.CMSProcessable;
    import org.bouncycastle.cms.CMSSignedData;
    * class for generating a RSA pkcs7-signature message.
    public class Signature2CMSSignedData2 {
    CertStore certStore;
    List certs = new ArrayList();
    List crls = new ArrayList();
    List signerInfs = new ArrayList();
    List signers = new ArrayList();
    public static final String DATA = PKCSObjectIdentifiers.data.getId();
    public static final String ENCRYPTION_RSA = "1.2.840.113549.1.1.1";
    private byte[] signatureData = null;
    private X509Certificate cert = null;
    private String digestOID = null;
    private String encOID = null;
    public Signature2CMSSignedData2() {
    public void addSignature(byte[] signatureData, X509Certificate cert, String digestOID) {
    this.signatureData = signatureData;
    this.cert = cert;
    this.digestOID = digestOID;
    this.encOID = ENCRYPTION_RSA;
    public void addCertificatesAndCRLs(CertStore certStore) throws Exception{
    try {
    Iterator it = certStore.getCertificates(null).iterator();
    while (it.hasNext()) {
    X509Certificate c = (X509Certificate) it.next();
    certs.add(new X509CertificateStructure((ASN1Sequence) makeObj(c.getEncoded())));
    Iterator it2 = certStore.getCRLs(null).iterator();
    while (it2.hasNext()) {
    X509CRL c = (X509CRL) it2.next();
    crls.add(new CertificateList((ASN1Sequence) makeObj(c.getEncoded())));
    catch (Exception e) {
    throw new Exception(e.getMessage());
    private DERObject makeObj(byte[] encoding) throws Exception {
    if (encoding == null) {
    return null;
    ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
    ASN1InputStream aIn = new ASN1InputStream(bIn);
    return aIn.readObject();
    public CMSSignedData generate(String signedContentType, CMSProcessable content, boolean encapsulate) throws Exception {
    try {
    ASN1EncodableVector digestAlgs = new ASN1EncodableVector();
    ASN1EncodableVector signerInfos = new ASN1EncodableVector();
    DERObjectIdentifier contentTypeOID = new DERObjectIdentifier(signedContentType);
    // add the SignerInfo objects
    Iterator it = signerInfs.iterator();
    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(digestOID), new DERNull());
    AlgorithmIdentifier encAlgId;
    encAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(encOID), new DERNull());
    digestAlgs.add(digAlgId);
    ASN1Set signedAttr = null;
    ASN1Set unsignedAttr = null;
    ASN1OctetString encDigest = new DEROctetString(signatureData);
    ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getTBSCertificate());
    ASN1InputStream aIn = new ASN1InputStream(bIn);
    TBSCertificateStructure tbs = TBSCertificateStructure.getInstance(aIn.readObject());
    IssuerAndSerialNumber encSid = new IssuerAndSerialNumber(tbs.getIssuer(), tbs.getSerialNumber().getValue());
    signerInfos.add(new SignerInfo(new SignerIdentifier(encSid), digAlgId, signedAttr, encAlgId, encDigest, unsignedAttr));
    ASN1Set certificates = null;
    if (certs.size() != 0) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    it = certs.iterator();
    while (it.hasNext()) {
    v.add( (DEREncodable) it.next());
    certificates = new DERSet(v);
    ASN1Set certrevlist = null;
    if (crls.size() != 0) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    it = crls.iterator();
    while (it.hasNext()) {
    v.add( (DEREncodable) it.next());
    certrevlist = new DERSet(v);
    ContentInfo encInfo;
    if (encapsulate) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    content.write(bOut);
    ASN1OctetString octs = new BERConstructedOctetString(bOut.toByteArray());
    encInfo = new ContentInfo(contentTypeOID, octs);
    else {
    encInfo = new ContentInfo(contentTypeOID, null);
    SignedData sd = new SignedData(new DERSet(digestAlgs), encInfo, certificates, certrevlist, new DERSet(signerInfos));
    ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, sd);
    return new CMSSignedData(content, contentInfo);
    catch (Exception e) {
    throw new Exception(e.getMessage());
    }Bye.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

  • Problem using workflow with ess leave requests

    Hello, I have been experiencing some problems using wf for approval with leave request in ess.
    I customized ws12300111 for request approval and it is working fine. But when we try to cancel a request in ess, there are strange things happening:
    - If the request is in status sent: the workflow gets in error.
    - If the request is already in db: it starts a new workflow (ws12300111).
    We don't want this because we have customized ws12300111 only for new requests. I have tried to customize absences in SPRO so that onlu new requests start the WS12300111, Onlu new requests have the workflow field filled with 12300111, but even like that, the WS12300111 starts whenever that is a cancelling or modification of a request.
    I have also tried using a different workflow for canceliing (WS12400007), but in this case there is an error in ess when we try to submit.
    This is really annoying, I have tried everything...

    Hello,
    "If the request is in status sent: the workflow gets in error."
    Please always say what the error is.
    " If the request is already in db: it starts a new workflow (ws12300111"
    You first have to find out how this is done. Look in SWEL, it's probably via some sort of CHANGED event.
    regards
    Rick Bakker
    hanabi technology

Maybe you are looking for

  • Can't log in to my account after system crash

    I'm looking for help with a bizarre problem that just started on my mac. I was using the computer (just using Safari, Mail, etc., nothing fancy) and got the message that my disk was full and I should quit some programs to free up space. I check my st

  • Delete duplicate values from a table

    Hi All I have a table like this table: id name   plan   code 1   sam  normal   5 1   sam  normal   6 1   sam  special  5 1   sam  Special  6I need to delete data in such a way that one entry with normal and one entry with special plan should remain a

  • How can I cancel an update download once it has started?

    Firefox asks me to download an update to version 3.6.24 every time I go online. I do not wish to do so at this time. However, I hit the download button by accident and it began the download. I have paused it, but I want to know how I may stop it alto

  • Wierd email download problem...losing messages

    Anyone else had this problem - you download messages on iPhone - and often get the dreaded "no content" or "did not download message from server" message - and then when you try to download message on primary computer the message never shows up? (And

  • OAS and/or WebDB

    Hello, all! I have a real quick question should I install WebDB and/or OAS on the same directory as $ORACLE_HOME or a different one. The reason I'm asking is that I tried and OAS replace all ORACLE executables and the libs are messed up big time...su