大佬教程收集整理的这篇文章主要介绍了org.postgresql.util.PSQLException:错误:在(或附近)的语法错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
表示SQL查询不正确。您可能需要将其更改为类似这样的内容。
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);
请注意,create语句(afaik)不是sql标准命令。因此,由于您使用的是PostgreSQL,因此需要将其更改为POSTGResql create语句。
我创建了一个Web应用程序,该Web应用程序可以通过maven eclipse部署在Heroku上。
组ID:org.glassfish.jersey.archetypes
工件ID:jersey-heroku-webapp
版本:2.17
我在本地主机上测试了该应用程序,POSTMAN
并且工作正常。我将其推送到heroku以便在servlet容器上对其进行测试,但是我得到520
OK
520,这只是我在SQLEXCEPTION中返回的数字。在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)
数据库类:
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,"
+ "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,con);
}
return status;
} catch (SQLException E) {
// TODO Auto-generated catch block
e.printStackTrace();
return status = 520;
}
}
以上是大佬教程为你收集整理的org.postgresql.util.PSQLException:错误:在(或附近)的语法错误全部内容,希望文章能够帮你解决org.postgresql.util.PSQLException:错误:在(或附近)的语法错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。