aspose file tools*
The moose likes JDBC and the fly likes Insert statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert statement" Watch "Insert statement" New topic
Author

Insert statement

Madmax
Greenhorn

Joined: Nov 13, 2002
Posts: 6
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

Joined: Jan 19, 2001
Posts: 4012
    
    6
"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert statement