Ana,
Thanks for your reply.
The solution you provide works fine. Is there a way to not hard-code the
getconnection ("jdbc:oracle:thin:@..","scott","sss") ?
Also, I saw a solution using "BeforeInsert" method in the PK class but the
container (I am testing with J2EE) never calls it. I am copying the code
from the message by Malcolm Sparks ..
public class CustomerPK implements java.io.Serializable {
public double id;
....
public void beforeInsert(java.sql.Connection conn) throws
java.sql.SQLException {
java.sql.Statement statement=conn.createStatement();
java.sql.ResultSet rs=statement.executeQuery("select
customer_seq.nextval from dual");
rs.next();
this.id=rs.getDouble(1);
}
}
This appears to be a cleaner way of doing but the container in my app never
calls the beforInsert. Did you have any luck with similar solutions.
Thanks a lot,
Subu
e-mail: [EMAIL PROTECTED]
> -----Original Message-----
> From: Bhattacharyya, Ana [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 25, 2000 12:52 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Primary Key - sequence from Oracle
>
>
> Hi Subu,
> u need to do something like this in your ejbCreate method for CMP
>
>
> public CustomerPK ejbCreate(String custname, int age)
> throws CreateException,
> RemoteException
> {
> System.out.println(" In create of Cust");
> this.custcode = getSeqCode();//This is the PK say..
> this.custname = custname;
> this.age = age;
>
> return null;
> }
>
> private int getSeqCode()
> {
>
> try
> {
> Connection con = getConnection();
> PreparedStatement ps = con.prepareStatement("select
> testseq.nextval from dual");
> ps.executeQuery();
> ResultSet rs = ps.getResultSet();
> int i = 0;
> while (rs.next())
> {
> i = rs.getInt(1);
> }
> rs.close();
> return i;
> }
> catch(Exception e)
> {
> e.printStackTrace();
> return 0;
> }
> }
>
> This will work. But I think there are lot other solutions for this ---
> namely one followed by IAS. U can check the archive for those.
> HTH
> Anamitra
>
> -----Original Message-----
> From: Vdaygiri, Subu [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 25, 2000 12:34 PM
> To: [EMAIL PROTECTED]
> Subject: Primary Key - sequence from Oracle
>
>
> In J2EE CMP (container - managed) bean, what changes I might
> need to make to
> the bean or PK class in order to use a sequence from Oracle
> to generate the
> primary key ?
>
> Thanks a lot for the help !!
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff EJB-INTEREST". For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff EJB-INTEREST". For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".