Re: [JBoss-user] Auto Incrementing Primary Key with PostgreSQL a ndJBoss

2001-07-27 Thread Ludovic Orban


How would you choose the next key manually ?

I mean: if the field was just an integer (not auto-incr), how would you get 
the value of the next primary key ?

Ludovic


--On vendredi 27 juillet 2001 11:47 +0200 Hermann RANGAMANA 
<[EMAIL PROTECTED]> wrote:

> It works only if you decide to generate yourself auto-incr value. But what
> folk are talking about is how to get a database generated auto-incr and
> map it with your entity bean.


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] Auto Incrementing Primary Key with PostgreSQL a ndJBoss

2001-07-27 Thread Ludovic Orban


And how to perform this with CMP ?

Ludovic


--On vendredi 27 juillet 2001 10:27 +0200 Federico Vesco 
<[EMAIL PROTECTED]> wrote:

> Hi.
> Maybe someone might be interested to the solution I adopted:
>
> private Integer insertRow (String projectName,int budget,java.sql.Date
> start,java.sql.Date end) throws SQLException {
>
>
>
>   String nextStatement="select nextval('project_idproject_seq')";
>   String insertStatement =
> "insert into project
> (\"projectName\",\"budget\",\"start\",\"end\") values ( ?
> , ? , ? , ? )";
>
>
>   PreparedStatement nextStmt =
> con.prepareStatement(nextStatement);
>   PreparedStatement prepStmt =
> con.prepareStatement(insertStatement);
>
>   prepStmt.setString(1, projectName);
>   prepStmt.setInt(2, budget);
>   prepStmt.setDate(3, start);
>   prepStmt.setDate(4, end);
>
>   ResultSet rsn=nextStmt.executeQuery();
>   rsn.next();
>   int i=rsn.getInt(1);
>   Integer result=new Integer(i);
>   nextStmt.close(); // In this way I obtain the value of the
>   auto-incrementing PK
>
>   prepStmt.executeUpdate();
>   prepStmt.close();
>
>
>
>   if(result!=null)
>   {  return result; }
>   else { return null;}
>
>
>}
>
>
> Rember that this solution works for PostgreSQL.
>
> Federico
>
> _
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> ___
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user





___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user