【发布时间】:2017-10-07 01:50:19
【问题描述】:
public static void main(String[] args) {
try {
Connection c = null;
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/postgres", // db
"postgres", // account
"ForOnlyOneTick1" // password
);
Object loc = Dimension.class;
PreparedStatement insertNew = c
.prepareStatement("CREATE TYPE loc AS (?);");
insertNew.setObject(1, loc);
insertNew.executeUpdate();
insertNew.close();
c.close();
} catch (Exception e) {
//e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
}
在那个例子中,我尝试在我的数据库中创建一个维度类型。 但它不起作用。
是否可以使用特定类型的 java 类创建列?
或者我可以只使用我的数据库知道的类型吗?
例如:
CREATE TYPE location AS (x int, y int, z int, name VARCHAR(15));
好的,但是如果我需要创建一个类型,问题仍然存在:
CREATE TYPE land AS (area Dimension, people ListPeople, probability int, cause Causes);
Dimension,ListPeople,Causes 是我的自定义类,其他类具有公共值。
【问题讨论】:
标签: java sql database postgresql types