Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
code


if (ae.getSource() == bpaid)
{
int k;

rs = pst.executeQuery();
String status = tfees.getText();
System.out.println(status);

String ss = "update fees set feesstatus= " + status + " where fees.sid=" + roll + "";
k = st.executeUpdate(ss);
if (k>0)
{
System.out.println("Record Is Updated");
}


status is the fees status paid / unpaid.
Posted
Updated 6-Apr-15 4:48am
v6
Comments
Sergey Alexandrovich Kryukov 2-Apr-15 0:35am    
In what line? Use the debugger...
—SA
Member 11520467 2-Apr-15 0:38am    
am doing in command prompt using notepad.
Xiao Ling 2-Apr-15 2:37am    
How could you see the null pointer exception? You probably can't even pass the code compilation.
Richard Deeming 2-Apr-15 7:58am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

1 solution

Looks like you have an extra double quotation character at the end of this line.
Java
String ss = "update fees set feesstatus= " + status + " where fees.sid=" + roll + ";

change to
Java
String ss = "update fees set feesstatus= " + status + " where fees.sid=" + roll;


Note: Using spaces in your code is not bad practice, it makes it more readable and it is easier to find this kind of errors.
I re-formatted your code and saw the extra character in an instant.
 
Share this answer
 
v2
Comments
Richard Deeming 2-Apr-15 7:59am    
You have copied the SQL Injection[^] vulnerability from the question.

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
George Jonsson 2-Apr-15 9:31am    
Well, that is correct, but sometimes you have to take it step by step. What I should have done is to point out that using string concatenation is a bad idea.
I would love to see your superior solution, but it seems to be missing.

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