Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert statement

 
Madmax
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I am trying to insert a simple statement with JDBC 2.0 driver. I have a connection manager class which managesdatabase connections.
We are using Tomcat 4.1.12 with Struts 1.2 and SQL Server 2000 as database, I am try to execute this method. The result says its a success, but the record does not display in the table. Could some one help me here?
Thanks,
Madmax.
private long insertProject()
throws
SQLException
{
long projectID = -1;
ResultSet rs = null;
/*------------------------------------------------------------------------
Build the prepared statement for the insert.
------------------------------------------------------------------------*/
PreparedStatement ps = buildSQLForProjectInsert();
try
{
/*----------------------------------------------------------------------
Insert the record into the project table.
----------------------------------------------------------------------*/
ps.execute();
/*----------------------------------------------------------------------
Verify that only one record was affected by the insert.
----------------------------------------------------------------------*/
if ( ps.getUpdateCount() == 1)
{
/*--------------------------------------------------------------------
Get value of the ID from the result set.
--------------------------------------------------------------------*/
ps.getMoreResults();
rs = ps.getResultSet();
projectID = getPrimaryKey( rs );
}
else
{
throw new SQLException ( "Invalid number of rows affected on insert." );
}
}
finally
{
close( rs );
close( ps );
}
return( projectID );
}
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Madmax",
Please change your display name to comply with our only rule at Javaranch, the famous naming policy. As this is the third time you've been asked, you risk having your account blocked if you continue to post with your current display name.
Now ain't that an offer you just can't refuse?

Pauline
change your display name
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic