Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

delete method using JDBC and Access

843854Apr 26 2005 — edited Apr 26 2005
I can't get my delete method to work:
// delete book
 	public void deleteBook(String isbn)
 	{
 		boolean deleted = false;
 		
 		try
 		{
 			doStatementQuery(bookSQLStatements.RemoveBook(isbn), 3, 1);
 			statement.close();
 			bookSQLStatements.CloseDatabase();
 			deleted = true;
 		}
 		catch(SQLException sqlException)
 		{
 			System.out.println(sqlException.toString());
 			deleted = false;
 		}
 		
 		if(deleted)
 		{
 			JOptionPane.showMessageDialog(null, "Book Details Relating to: " + isbn + " have been deleted", "Deletion Confirmation", 1);
 		}
 		else
 		{
 			JOptionPane.showMessageDialog(null, "It has not been possible to delete Book Details relating to: " + isbn + "!", "Deletion Confirmation", 1);
 		}
 	}
 	
 	// this method creates a statement from the query passed as an argument
 	private void doStatementQuery(String query, int execute, int connect)
 	{
 		int result = 0;
 		resultSet = null;
 		statement = null;
 		connection = null;
 		
 		switch(connect)
 		{
 			case 1: connection = bookSQLStatements.OpenDatabase();
 			break;
 		}
 		
 		try
 		{
 			statement = connection.createStatement();
 			System.out.println(query);
 			
 			if(execute == 1)
 			{
 				resultSet = statement.executeQuery(query);	
 			} 	
 			
 			else if(execute == 2)
 			{
 				result = statement.executeUpdate(query);
 			}		
 			
 			else if (execute == 3) 
 			{ 
				statement.execute(query);
			}
		}
 		catch(SQLException sqle)
 		{
 			System.out.println(sqle.toString());
 		}
 	}

// method to remove a book from the database
 	public String RemoveBook(String isbnIn)
 	{
 		return "DELETE FROM Book WHERE ISBN = '" + isbnIn + "'";
 	}
is about all of the methods that it relates to, it's not throwing an error but it's also not working. Thank you for any help that you can give, Wonkey
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2005
Added on Apr 26 2005
16 comments
300 views