简体   繁体   English

org.postgresql.util.PSQLException:错误:“(”或附近的语法错误

[英]org.postgresql.util.PSQLException: ERROR: syntax error at or near “(”

I have craeted a Web Application that can be deployed on Heroku by maven eclipse. 我创建了一个Web应用程序,该Web应用程序可以通过maven eclipse部署在Heroku上。

Group Id: org.glassfish.jersey.archetypes 组ID:org.glassfish.jersey.archetypes

Artifact Id: jersey-heroku-webapp 工件ID:jersey-heroku-webapp

version: 2.17 版本:2.17

I tested the appication on the localhost and POSTMAN and it works fine. 我在本地主机和POSTMAN上测试了该应用POSTMAN ,并且工作正常。 I pushed it to heroku to test it on servlet container but I am getting 520 OK 520 it is just a number that I return in the SQLEXCEPTION. 我将其推送到heroku以便在servlet容器上对其进行测试,但是我得到520 OK 520,这只是我在SQLEXCEPTION中返回的数字。 IN the Heroku log I found this error: 在Heroku日志中,我发现此错误:

2015-05-13T13:10:37.364388+00:00 app[web.1]:    at java.lang.Thread.run(Thread.j
ava:745)
2015-05-13T13:10:37.389547+00:00 app[web.1]: org.postgresql.util.PSQLException:
ERROR: syntax error at or near "("
2015-05-13T13:10:37.389560+00:00 app[web.1]:   Position: 45
2015-05-13T13:10:37.389740+00:00 app[web.1]:    at org.postgresql.core.v3.QueryE
xecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)

Database class: 数据库类:

public class Database {


    public Database() {

    }

    public void drivercConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("jar works :) ");

        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static Connection getConnection() throws URISyntaxException, SQLException {

        URI dbUri = new URI(System.getenv("DATABASE_URL"));
        String username = dbUri.getUserInfo().split(":")[0];
        String password = dbUri.getUserInfo().split(":")[1];
        String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':'
                + dbUri.getPort() + dbUri.getPath();

        Connection con = DriverManager.getConnection(dbUrl, username, password);
        return con;
    }

    public int insertData(String mac, int route, double latD, double longD) {
        int status = 201;

        drivercConnection();

        try {
            Connection con = null;
            try {
                con = getConnection();
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


            // Create a statement
            Statement stt = con.createStatement();

            DatabaseMetaData dbm = con.getMetaData();

            ResultSet tables = dbm.getTables(null, null, "bus", null);

            if (tables.next()) {
                // stt.execute("ALTER TABLE bus AUTO_INCREMENT = 1");

                return insertRecord(mac, route, latD, longD, status, con);

            } else {
                // Create bus table
                stt.execute("CREATE TABLE IF NOT EXISTS bus"
                        + "(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
                        + "mac VARCHAR(30) NOT NULL UNIQUE,"
                        + "route int(11) NOT NULL,"
                        + "latitude FLOAT(10,6) NOT NULL,"
                        + "longitude FLOAT(10,6) NOT NULL,"
                        + "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");

                stt.execute("CREATE EVENT IF NOT EXISTS  AutoDelete "
                        + "ON SCHEDULE EVERY 3 MINUTE "
                        + "DO "
                        + "DELETE FROM bus WHERE created_at < (NOW() - INTERVAL 3 MINUTE)");

                stt.execute("SET GLOBAL event_scheduler = ON");

                first_data_insert(mac, route, latD, longD, con);

            }
            return status;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return status = 520;

        }
    }

that indicate the sql query is not right. 表示sql查询不正确。 you might want to change it into something like this. 你可能会想改变它弄成这个样子。

DROP TABLE IF EXISTS bus;

CREATE TABLE bus( 
id SERIAL PRIMARY KEY,
mac VARCHAR(30) NOT NULL UNIQUE,
route int NOT NULL,
latitude numeric(10,6) NOT NULL,
longitude numeric(10,6) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

Note that create statement (afaik) is not a sql standard command. 请注意,create语句(afaik)不是sql标准命令。 So, because you're using postgresql, you need to change it into postgresql create statement. 所以,因为你使用PostgreSQL,你需要把它转变成PostgreSQL的创建语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" org.postgresql.util.PSQLException:错误:在“with”处或附近出现语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near "with" org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “:” org.postgresql.util.PSQLException:错误:语法错误在“$ 1”或附近 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1” org.postgresql.util.PSQLException:错误:“ 7”或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “7” org.postgresql.util.PSQLException:错误:“)”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “)” org.postgresql.util.PSQLException:错误:“-”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “-” org.postgresql.util.PSQLException:错误:Java 中«,» 附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error near «,» in Java Java 中的错误:org.postgresql.util.PSQLException:错误:语法错误附近; - Error in Java: org.postgresql.util.PSQLException: ERROR: syntax error near ; date_trunc org.postgresql.util.PSQLException:错误:“ $ 1”或附近的语法错误 - date_trunc org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM