【发布时间】:2012-05-26 00:15:47
【问题描述】:
我想用JDBC输入一个命令来创建一个表,但是在第一次编译后,当表已经生成时,下一个都会抛出异常。我不明白这怎么可能,因为我已经把 [IF NOT EXISTS] 术语放在那里,所以应该没有 SQL 错误。
public class Test
{
public static void main(String[] args)
{
try
{
Connection conn = BazaDanych.Polacz();
Statement stat = conn.createStatement();
String command = "CREATE TABLE [IF NOT EXISTS] testowatabela2 (id INTEGER, wartosc DOUBLE PRECISION);";
stat.execute(command);
}
catch(SQLException e)
{
System.out.println("SQL Exception in Test");
}
}
}
【问题讨论】:
-
将
catch(SQLException e) {更改为catch(SQLException e) { e.printStackTrace();并复制/粘贴输出。 -
有些数据库不支持 IF NOT EXISTS 结构。
-
-
IF NOT EXISTS 应该放在方括号中吗?
-
org.postgresql.util.PSQLException:错误:错误在或接近“[”位置:14 在 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102) 在 org .postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835) 在 org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) 在 org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java :500) 在 org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags
标签: java sql database postgresql jdbc