JDBC将Postgres查询中的表大写 [英] JDBC capitalizing the table in my postgres query

查看:345
本文介绍了JDBC将Postgres查询中的表大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下代码

/**
 * @param args
 */
public static void main(String[] args) throws SQLException {
    System.out.println("starting");

    org.postgresql.Driver driver = new org.postgresql.Driver();
    DriverManager.registerDriver(driver);

    Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/epcfe/", "postgres", "aap123!");

    Statement st = con.createStatement();
    st.executeQuery("select * from epcfeschema.PRODUCT");

    System.out.println("done");
}

我不断得到Exception in thread "main" org.postgresql.util.PSQLException: ERROR: relation "epcfeschema.product" does not exist

如果我使用小写名称产品创建表,则可以正常工作,但我需要使用该表才能使用所有大写字母的表.如何防止JDBC降低表的大小写?

If I create a table with the lowercase name product this works fine but I need it to work for tables with all caps. How do I keep JDBC from lowercasing my table?

推荐答案

如果这是休眠问题,请尝试以下操作:

If it's a hibernate issue, try this:

@Entity
@Table(name = "\"PRODUCT\"")
public class Product { // ...

或更妙的是,让生活变得轻松:登录postgres并重命名表!

Or better yet, make your life easy: log on to postgres and rename the table!

ALTER TABLE "PRODUCT" rename to product;

(当然,其他代码可能取决于帽子名称...)

(Of course, other code may depend on the cap name...)

这篇关于JDBC将Postgres查询中的表大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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