Hi all , 
     I am using postgresql7.0 , linux6.1 , jboss-FINAL_2.0 

     To facilitate autogenerate primary key in jboss , I have code below
: 

     I have some question regarding the matter ... Is there any thread
access problems with it  ?.
     Are connection is pooling ?

     Anyone have any comment regarding the code , please feel free to
comment . I need some advice on this .

    Thanks wt

  
 private Connection getConnection() throws SQLException{
   DataSource ds = null;
    try{
      Context ctx = new InitialContext();
      ds = (DataSource)ctx.lookup("java:comp/env/jdbc/PostgresDS");
    }
    catch(NamingException ne){
     ne.printStackTrace();
    }
   return ds.getConnection();

  }


  public GeneratePK ejbCreate(String name) throws CreateException {

    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try{
      conn = this.getConnection();
      ps = conn.prepareStatement("Select NEXTVAL('test_seq') from
test_seq");
      rs = ps.executeQuery();

      if(rs.next()){
       this.id = rs.getString("nextval");
       }
    }
    catch(SQLException se){
     se.printStackTrace();
    }
    finally{
     try{
       if(rs != null) rs.close();
       if(ps != null) ps.close();
       if(conn != null) conn.close();
     }catch(SQLException se){
      se.printStackTrace();
     }
    }

    this.name = name;

    return null;
  }


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]

Reply via email to