JDBC将Postgres查询中的表大写

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...)