Update column data in MySQL table
P粉358281574
P粉358281574 2024-01-10 17:31:14
0
1
431

I'm just learning and don't understand how to update individual columns in a table, I'm using MySQL. The table name is card and I want to update the pincode column. java.sql.SQLSyntaxErrorException: There is an error in your SQL syntax; check the manual for your MySQL server version for the correct syntax to use near line 1 "UPDATE COLUMN pincode = strPincodeNew"

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("\n\n==== 输入新的PIN码 ====\n");
                                    pincodeNew = scanner.nextInt();
                                }
                                String strPincodeNew = String.valueOf(pincodeNew);
                                operation.newPC1(strPincodeNew, cardNumber);
                                System.out.println("PIN码已成功更改");

Rewritten different commands

P粉358281574
P粉358281574

reply all(1)
P粉482108310

Please try the following. If necessary, please correct the card number listing:

public void newPC1(String strPincodeNew, String cardNumber) throws SQLException {
        try (Connection c = Database.connection();
            PreparedStatement ps = c.prepareStatement("UPDATE card SET pincode = ? WHERE card_number = ?")) {
            ps.setString(1, strPincodeNew);
            ps.setString(2, cardNumber);
            ps.executeUpdate();
        }
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template