You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java数据映射器创建MySQL用户时报‘Unknown column 'phone'’字段错误求助

Fixing the "Unknown column 'phone' in 'field list'" Error

Hey there! Let's break down what's going on here and fix that error quickly.

The Root Cause

Your error message says MySQL can't find a column named phone, but looking at your SQL statement:

String SQL = "INSERT INTO Users (email, password, phonenumber, post, adress, role) VALUES (?, ?, ?, ?, ?, ?)";

You're referencing a column called phonenumber instead of phone. This means your actual Users table in MySQL has a column named phone for the user's phone number, not phonenumber—the mismatch between your code and the database schema is causing the error.

Step-by-Step Fixes

  1. Verify your table structure first
    Run this MySQL command to confirm the exact column names in your Users table:

    DESCRIBE Users;
    

    This will list all columns, and you'll see that the phone number column is indeed named phone (not phonenumber).

  2. Update your SQL statement
    Change phonenumber to phone in your Java code's SQL string:

    String SQL = "INSERT INTO Users (email, password, phone, post, adress, role) VALUES (?, ?, ?, ?, ?, ?)";
    
  3. Bonus: Check for other typos
    I noticed you wrote adress instead of address (missing a 'd'). This might not cause an error now if your table uses that misspelled column name, but it's worth correcting for consistency and to avoid future issues.

Quick Double-Checks

  • Make sure the order of parameters in your PreparedStatement matches the order of columns in the SQL statement (so the phone number value is being passed to the correct column).
  • Confirm you're connecting to the right MySQL database instance—sometimes people accidentally connect to a test database with a different schema.

内容的提问来源于stack exchange,提问作者kristheman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:37:20