File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Insert statement" Watch "Insert statement" New topic

Insert statement


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?
private long insertProject()
long projectID = -1;
ResultSet rs = null;
Build the prepared statement for the insert.
PreparedStatement ps = buildSQLForProjectInsert();
Insert the record into the project table.
Verify that only one record was affected by the insert.
if ( ps.getUpdateCount() == 1)
Get value of the ID from the result set.
rs = ps.getResultSet();
projectID = getPrimaryKey( rs );
throw new SQLException ( "Invalid number of rows affected on insert." );
close( rs );
close( ps );
return( projectID );
Pauline McNamara

Joined: Jan 19, 2001
Posts: 4012
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?

change your display name
I agree. Here's the link:
subject: Insert statement
It's not a secret anymore!