【发布时间】:2021-06-21 08:02:27
【问题描述】:
Postgres JDBC 驱动程序未返回 PGAdmin 中显示的确切错误行号。当我运行以下程序时:
import java.sql.*;
public class Test {
public static void main(String[] args) {
String query = "SELECT table_name, table_type\n" +
" FROM information_schema.tabls\n" +
" WHERE table_schema='public'\n" +
" AND table_type in ('BASE TABLE','VIEW') ORDER BY table_type, table_name;";
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres")) {
System.out.println("Connected to PostgreSQL database!");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
System.out.printf("%-30.30s %-30.30s%n", resultSet.getString("table_name"), resultSet.getString("table_type"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
我收到以下错误:
org.postgresql.util.PSQLException: ERROR: relation "information_schema.tabls" does not exist
Position: 38
但是当我在 pgadmin4 上运行相同的查询时,我收到以下错误:
ERROR: relation "information_schema.tabls" does not exist
LINE 2: FROM information_schema.tabls
^
SQL state: 42P01
Character: 38
我也想要java程序中的行号。我怎样才能得到它?
【问题讨论】:
-
你得到了查询中的位置,你需要在你的Java程序中自己计算行号
标签: java postgresql jdbc pgadmin-4