如何修复语法错误“(”?

时间:2021-02-18 02:40:38

标签: java postgresql jdbc ddl

现在我使用 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, "("
我该如何解决这个错误?
如果你知道这个解决方案,你能教我吗?

1 个答案:

答案 0 :(得分:2)

字符串中有两个错误。

  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"
                    + ")";
相关问题