与Heroku的Java JDBC连接 [英] Java JDBC Connection with Heroku

查看:93
本文介绍了与Heroku的Java JDBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Heroku上创建Java Web App.将应用程序连接到Heroku数据库时,我遇到了一个问题: org.postgresql.util.PSQLException:错误:关系"sc_user"不存在

I'm trying to create a Java Web App on Heroku. When connecting the App to Heroku Database I encountered a Issue: org.postgresql.util.PSQLException: ERROR: relation "sc_user" does not exist

连接部分是:

URI dbUri = new URI(System.getenv("DATABASE_URL"));
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath();

BasicDataSource connectionPool = new BasicDataSource();

if (dbUri.getUserInfo() != null) {
    connectionPool.setUsername(dbUri.getUserInfo().split(":")[0]);
    connectionPool.setPassword(dbUri.getUserInfo().split(":")[1]);
}
connectionPool.setDriverClassName("org.postgresql.Driver");
connectionPool.setUrl(dbUrl);
connectionPool.setInitialSize(3);

Connection conn = connectionPool.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM SC_User");

我在Heroku仪表板上看到池中使用了3个连接,但是最后一行抛出异常,说没有关系sc_user.

I see on Heroku Dashboard that 3 connections are used from pool, but the last line throws exception saying no relation sc_user.

我使用附加工具Adminium创建了表,命令中是否缺少某些内容?感谢您的帮助!

I created the table with add-on tool Adminium, is there something i'm missing in the commands? Thanks for your help!

推荐答案

在postgres中使用Upper Letter创建一列时,DBMS在"SC_User" si之间使用它,以防万一您的列在高字母中,您必须使用:

When you create a column in postgres with Upper Letter the DBMS use it between "SC_User" si in case your column is in upper Letter you have to use :

stmt.executeQuery("SELECT * FROM \"SC_User\""); 
//--------------------------------^--------^

否则,您必须使用小写的正确名称

else you have to use the correct name with lowercase

stmt.executeQuery("SELECT * FROM sc_user");
//---------------------------------^^


在此详细了解: 无法查询具有大写字母列名称的Postgres数据库


read more about that here : Cannot query Postgres database that has column names with capital letters

这篇关于与Heroku的Java JDBC连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆