I’m just learning and I don’t understand how to update a separate column in the table, I use MySQL. The table is called card, I want to update the pincode column.
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘UPDATE COLUMN pincode = strPincodeNew’ at line 1
public void newPC1(String strPincodeNew, String cardNumber) {
try {
Connection c = Database.connection();
Statement stmt11 = c.createStatement();
String sql12="ALTER TABLE card UPDATE COLUMN pincode = strPincodeNew";
stmt11.executeUpdate(sql12);
while (pincodeNew>=....) {
System.out.println("nn==== Enter a new PIN code ====n");
pincodeNew = scanner.nextInt();
}
String strPincodeNew = String.valueOf(pincodeNew);
operation.newPC1(strPincodeNew, cardNumber);
System.out.println("PIN code successfully changed");
Rewrote different commands
2
Answers
What you want is to change a column in a row. So you need to select both.
Likely you want to do something like
You need to have one row (via an
INSERT
statement) in the table, before you can update something.Try the following. You need to correct the card number column name where necessary: