【问题标题】:How can I fix syntax erroor "("?如何修复语法错误“(”?
【发布时间】:2021-02-18 02:40:38
【问题描述】:

现在我使用 postgreSQL 并制作库存管理程序。
在我制作表格时,发生了错误。
我的代码是这样的!

import java.sql.Connection;
import java.sql.Statement;

public class Create_Table {

    public static void main(String[] args) {
        
        Connection connection = null;
        Statement statement = null;
        
        ConnectDB obj_ConnectDB = new ConnectDB();
        
        connection = obj_ConnectDB.get_connection();
        
        try {
            String query = "CREATE TABLE IF NOT EXISTS stockmanagement ("
                    + "ID SERIAL primary key, "
                    + "Name varchar(20), "
                    + "Unit_price numeric(15,1), "
                    + "Qty INT(20),"
                    + "Imported_Date Date,"
                    + ")";
            statement = connection.createStatement();
            statement.executeUpdate(query);
            System.out.println("finished");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

错误内容如下。
error : syntax error, "("
如何解决此错误?
如果你知道这个解决方案,你能教我吗?

【问题讨论】:

  • 你在哪里发现in the manual int(20) 在 Postgres 中有效?
  • 哦,这是我的错误。谢谢你的评论!祝你今天过得愉快! XD

标签: java postgresql jdbc ddl


【解决方案1】:

字符串中有两个错误。

  1. 末尾多一个逗号
  2. INT(20) 不合法

这应该可以工作

            String query = "CREATE TABLE IF NOT EXISTS stockmanagement ("
                    + "ID SERIAL primary key, "
                    + "Name varchar(20), "
                    + "Unit_price numeric(15,1), "
                    + "Qty INT,"
                    + "Imported_Date Date"
                    + ")";

【讨论】:

  • 我认为 INT(20) 应该替换为 BIGINT 而不是 INT,假设 20 旨在传达位数。
  • 谢谢你!!因为你,我解决了这个问题!祝你今天过得愉快! XD
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-09
  • 2017-08-30
  • 2023-03-09
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多