{
  "id": "java/sql-data-truncation",
  "signature": "java.sql.DataTruncation: Data truncation on column 'X'",
  "signature_zh": "java.sql.DataTruncation: 列'X'上的数据截断",
  "regex": "java\\.sql\\.DataTruncation: Data truncation on column '(.*?)'",
  "domain": "java",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "DataTruncation occurs when a JDBC driver attempts to insert or update a value that exceeds the column's defined length or precision in the database schema.",
  "root_cause_type": "generic",
  "root_cause_zh": "DataTruncation 发生在 JDBC 驱动程序尝试插入或更新超过数据库模式中列定义长度或精度的值时。",
  "versions": [
    {
      "version": "Java 8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MySQL Connector/J 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PostgreSQL JDBC 42.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "H2 2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Increases database storage and may allow invalid data, but truncation can still occur if the new limit is again exceeded.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not address the actual data size mismatch; the truncation still happens at the database level.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate and truncate the data in Java code before insertion. For example: if (value.length() > columnMaxLength) { value = value.substring(0, columnMaxLength); }",
      "success_rate": 0.85,
      "how": "Validate and truncate the data in Java code before insertion. For example: if (value.length() > columnMaxLength) { value = value.substring(0, columnMaxLength); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase the column size in the database schema using ALTER TABLE: ALTER TABLE my_table MODIFY COLUMN my_column VARCHAR(500); and ensure application logic respects the new limit.",
      "success_rate": 0.9,
      "how": "Increase the column size in the database schema using ALTER TABLE: ALTER TABLE my_table MODIFY COLUMN my_column VARCHAR(500); and ensure application logic respects the new limit.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate and truncate the data in Java code before insertion. For example: if (value.length() > columnMaxLength) { value = value.substring(0, columnMaxLength); }",
    "Increase the column size in the database schema using ALTER TABLE: ALTER TABLE my_table MODIFY COLUMN my_column VARCHAR(500); and ensure application logic respects the new limit."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/javase/8/docs/api/java/sql/DataTruncation.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-01-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}