Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If I have build a software and any user uses it. If user enters any details say he wants to update any of his entry and he enters wrong details which are not available in table.

Then how can I make sure that user is informed about error by displaying message on screen may be on any textfield.

Is there any such query available. Or any other ways to do it.

May be if user wants to delete data in table and he enters ID not available in table then he must be informed about that by displaying any message on screen.


===================
Java
private static void updatepeasinfo(String wbst, String email, String passwd, String key, String passky) throws SQLException
{
    wbst = wbst.toUpperCase();
stmt = conn.createStatement();
String query = "UPDATE peasinfo SET password = ?, encrykey = ? WHERE website = ? and email = ? and pass = ?";

try{
java.sql.PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setString(1,passwd);
pstmt.setString(2,key);
pstmt.setString(3,wbst);
pstmt.setString(4,email);
pstmt.setString(5,passky);
pstmt.executeUpdate();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}

========where should I gave the message that record to update don't exist============
Posted
Updated 25-Mar-12 0:21am
v4
Comments
OriginalGriff 24-Mar-12 10:35am    
What kind of project is it? Web? Winforms? WPF?
CurrentlyBE 24-Mar-12 13:35pm    
Sir its an application which uses database to store data, so as it can be retrieved, updated, deleted whenever required...
CurrentlyBE 24-Mar-12 15:09pm    
no comments nor any answers yet... its urgent deadline is near...
Sergey Alexandrovich Kryukov 24-Mar-12 18:48pm    
Did you see a comment by OriginalGriff? You did answer the question; how can you hope for the answer? Tag application type or UI library you want to use.
--SA
[no name] 25-Mar-12 2:31am    
Nobody is here to achieve your deadline.

Use IF EXISTS in the query and if exists then update else select string that record not found...

Regards
 
Share this answer
 
Comments
CurrentlyBE 27-Mar-12 8:19am    
IF EXISTS ( our query for update or delete)

will this be the syntax
mhwasim 27-Mar-12 8:35am    
pseudo something like bleow
IF EXISTS (select null from table1 where column1 = @Val)
BEGIN
UPDATE table set column2 = @NEWval where column1 = @Val
SELECT 'Rec updated'
END
ELSE
SELECT 'Rec not found'
CurrentlyBE 28-Mar-12 14:14pm    
Thanks but this goes with SQL programming but how we write it in Java as I mentioned an update eg.. WE need to update password and key where website=? email=? and pass=?
Have you thought of perhaps implement some type of validation on your controls, or before submission or even Exception Handling?
 
Share this answer
 
Handle the error on the application side and then either display it to the user or log it into a file that a user can later examine for errors.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900