import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
public class UpdateRecord implements ActionListener {
private ScrollingPanel fields;
private JTextArea output;
private Connection connection;
public UpdateRecord(Connection c, ScrollingPanel f, JTextArea o) {
connection = c;
fields = f;
output = o;
}
public void actionPerformed(ActionEvent e)
{
try{
Statement statement = connection.createStatement();
if (!fields.id.getText().equals(""))
{
String query = "UPDATE Grades SET " +
"FirstName='" + fields.first.getText() +
"', LastName = '" + fields.last.getText() +
"', Quiz1 = '" + fields.Quiz1.getText() +
"', Quiz2 = '" + fields.Quiz2.getText() +
"', Quiz3 = '" + fields.Quiz3.getText() +
"', MP1 = '" + fields.MP1.getText() +
"', MP2 = '" + fields.MP2.getText()+
"', FE = '" + fields.FE.getText() +
"' WHERE id=" + fields.id.getText();
output.append("\nSending Query: " +
connection.nativeSQL(query) + "\n" );
int result = statement.executeUpdate(query);
if(result == 1)
output.append("\nUpdate Succesful\n");
else{
output.append("\nUpdate Failed\n");
fields.first.setText("");
fields.last.setText("");
fields.Quiz1.setText("");
fields.Quiz2.setText("");
fields.Quiz3.setText("");
fields.MP1.setText("");
fields.MP2.setText("");
fields.FE.setText("");
}
statement.close();
}
else
output.append("\nYou may only update an " +
"existing record. Use Find to " +
"locate the record, then " +
"modify the information and " +
"press Update. \n");
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
output.append(sqlex.toString());
}
}
}
What's The Problem In This Syntax... Everytime I'm Always Trying To Update A Record There Is A Message Saying: "Update Syntax Error"... What Will I Do...
Please Help Me Tnx...