Results 1 to 13 of 13
- 07-17-2010, 04:14 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
Table is not updated ,java script is fine
i have a following java script in which i want to change username of student in the table ,everything is fine in good even ps.executeUpdate() is working ,but when i go to table and write code select * from tablename,still the previous username is there ,
The code is
if((!t1.getText().equals("")) && (!t2.getText().equals("")) && (!t3.getText().equals("")) && (!t4.getText().equals("")))
{
try {
enteruser = t4.getText();
enterpass = t1.getText();
newuser = t2.getText();
confirm = t3.getText();
PreparedStatement ps3 = con.prepareStatement("select * from sreg where username=?");
ps3.setString(1, enteruser);
ResultSet rs1 = ps3.executeQuery();
rs1.next();
getuser = rs1.getString(4);
getuser=getuser.trim();
getpass = rs1.getString(12);
getpass=getpass.trim();
rs1.close();
ps3.close();
System.out.println(getuser);
System.out.println(getpass);
if (enteruser.equals(getuser)) {
if (getpass.equals(enterpass)) {
PreparedStatement ps4 = con.prepareStatement("update sreg set username=? where username=?");
ps4.setString(1, newuser);
ps4.setString(2, enterpass);
System.out.println("Before");
ps4.executeUpdate();
System.out.println("After");
JOptionPane.showMessageDialog(this, "Successfully Updated");
} else {
JOptionPane.showMessageDialog(this, "Please Enter Correct Current Password");
}
} else {
JOptionPane.showMessageDialog(this, "Please Enter Correct Current Username");
}
} catch (SQLException ex) {
Logger.getLogger(password.class.getName()).log(Lev el.SEVERE, null, ex);
}
}
else
{
JOptionPane.showMessageDialog(this,"Please Enter All the Filelds");
}
Note: System.out.println("Before");
System.out.println("After"); are working ,means ps4.executeUpdate(); is working,,
Somebody Please help to resolve it
ThanksLast edited by amritpalpathak; 07-17-2010 at 04:25 PM.
- 07-17-2010, 04:25 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Properly close your PreparedStatment (ps4), your Connection(s) and entire database at the end.
kind regards,
Jos
- 07-18-2010, 05:20 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
I have simple close prepared statement as
ps4.close();
still error is there
@jos ,the messsage "Successfully Updated " is coming but when i go to table and check username ,still previous username is there
- 07-18-2010, 07:41 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
I think your update statement is incorrect and I suspect you're filling in password for an old username).Java Code:if (enteruser.equals(getuser)) { if (getpass.equals(enterpass)) { PreparedStatement ps4 = con.prepareStatement("update sreg set username=? where username=?"); ps4.setString(1, newuser); ps4.setString(2, enterpass);
kind regards,
Jos
- 07-18-2010, 08:29 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
what do u mean by
"I think your update statement is incorrect and I suspect you're filling in password for an old username)."
I have a table sreg with column username at the back end,and in my code i just trying to update it from user,
You can see there is no error in preparedstatement (Update);
if preparedstatement is false,then why the message"Successfully updated" is coming, it means the prepared statement executed well thats why message is coming,,
Regards
Amrit pal pathak
- 07-18-2010, 08:39 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Check your update statement: you want to update something where the existing username == enterpass. That doesn't make sense semantically; of course it isn't a syntax error and the update succeeds (by doing nothing probably), but no user is updated; in simple terms: your parameter values to the PreparedStatement are incorrect, i.e. username != password.
kind regards,
Jos
- 07-18-2010, 09:33 AM #7
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
You was right josAh, i was passing (enterpass) instead to (enteruser),thats the mistake
ps4.setString(2, enterpass); /* This was wrong
ps4.setString(2, enteruser); /*This is write
Thanks a lot JosLast edited by amritpalpathak; 07-18-2010 at 11:27 AM.
- 07-18-2010, 09:44 AM #8
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
Now help me to solve other problem in this script
check out the following Statement from below,
PreparedStatement ps3 = con.prepareStatement("select * from sreg where username=?");
This is the modified form of above code
Problem is that,If i pass correct username(that already exist in database ),script is going well, rs1 and retrieve the column from table with respect to enter username that match with the username exist in backend and finally password is updated susssfully
Now the thing is that, if i pass wrong username(that is not exist in table ) then the error comes
"Invalid cusror state" ... I have to Print a message(JOptionPane.showMessageDialog(this, "Please Enter Correc username") when user enter a wrong username
what should be the code(condition) to print the message if entered username is wrong
The Code is
if((!t1.getText().equals("")) && (!t2.getText().equals("")) && (!t3.getText().equals("")) && (!t4.getText().equals("")))
{
try {
enteruser = t4.getText();
enterpass = t1.getText();
newpass = t2.getText();
confirm = t3.getText();
PreparedStatement ps3 = con.prepareStatement("select * from sreg where username=?");
ps3.setString(1, enteruser);
ResultSet rs1 = ps3.executeQuery();
rs1.next();
getuser = rs1.getString(4);
getuser=getuser.trim();
getpass = rs1.getString(12);
getpass=getpass.trim();
rs1.close();
ps3.close();
if (enteruser.equals(getuser)) {
System.out.println(enterpass);
if (enterpass.equals(getpass)) {
if(newpass.equals(confirm))
{
PreparedStatement ps4 = con.prepareStatement("update sreg set choosepassword=?,repeatpassword=? where username=?");
ps4.setString(3, enteruser);
ps4.setString(1, newpass);
ps4.setString(2, confirm);
ps4.executeUpdate();
JOptionPane.showMessageDialog(this, "Successfully Updated");
}
else
{
JOptionPane.showMessageDialog(this,"Please Enter Same Password Again To Confirm");
}
}
else {
JOptionPane.showMessageDialog(this, "Please Enter Correct Current Password");
}
} else {
JOptionPane.showMessageDialog(this, "Please Enter Correct Username");
}
} catch (SQLException ex) {
Logger.getLogger(password.class.getName()).log(Lev el.SEVERE, null, ex);
}
}
else
{
JOptionPane.showMessageDialog(this,"Please Enter All Fields");
}
Thanks
- 07-18-2010, 09:44 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
You're welcome; it can be hard to scrutinize your own code and spot the bug; when that happens to me I move away from the code and look again a half an hour later or so; most of the time I can see my mistake immediately.
<pedantic mode>
Of course I was right, I'm always right ... except when I'm wrong but those occasions don't count ;-)
</pedantic mode>
kind regards,
Jos
- 07-18-2010, 11:25 AM #10
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
please reply for above code?
i mean ,can we search the entered username within table(whole fields) so that if it match ,i will be the solution to my problem,further i can proceed ..
how to search a table for values enter by user?
what will be code?
HelpLast edited by amritpalpathak; 07-18-2010 at 11:48 AM.
- 07-18-2010, 11:51 AM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
You could've figured that out yourself by reading the API documentation for the ResultSet interface. If you query for a non-existing user (the user name is not in your table) the ResultSet will be empty, so your first resultset.next() call will return false, indicating that there is no 'next' row in the empty resultset.
kind regards,
Jos
- 07-18-2010, 12:08 PM #12
Member
- Join Date
- Jun 2010
- Posts
- 17
- Rep Power
- 0
i hope u didnt get my mean
when user enter a existing username suppose he/she enter it wrong ..Now the whole have no meaning because it fails in its first condition (false username)
i have a table name "sreg" with column of name "username"
now what i want,,, the entered username by user should be first search with all the entries in column "username", if it match,then we have to detect it in someway(e.g. we can update a variable like a++,, or can make a flag true or false), this is simple, but tell me how to make a search on table or column with value enter by user from front end... i hope u will get my mean now..
Thanks
- 07-18-2010, 12:17 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
is it fine that my java programs sharing same JavaBean?
By anthrax in forum New To JavaReplies: 1Last Post: 01-27-2010, 09:20 AM -
java script
By satti in forum Web FrameworksReplies: 0Last Post: 06-09-2009, 08:53 AM -
Program working fine on netbeans but not when run with jar file
By nvlachos in forum Advanced JavaReplies: 2Last Post: 03-16-2009, 07:52 PM -
application is not running please fine the solution for it.
By jagadeeshchinni in forum New To JavaReplies: 4Last Post: 09-28-2008, 10:14 AM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks