JDBC自定义类型映射顺序问题

时间:2019-09-05 10:30:07

标签: java oracle jdbc spring-jdbc

嗨,我使用springjdbc在oracle中调用storedprocedure。我有storedprocedure和我的输出属性自定义udt对象。在我的Java代码中,我想将此类型用作java类,为此我创建了自定义类并实现SQLData及其可以。但是我的问题是,如果数据库中的udt属性顺序更改了 像第一种情况一样,city是我在udt中的3号参数,state是4号。而我的java类的顺序相同,但是我只切换了参数顺序,并且那个时间值设置错误(将City值设置为state并将state值设置为city) 有没有办法控制这种订单混乱。

>  CREATE TYPE ADDRESS   (
    >     NUM INTEGER, (1)
    >     STREET VARCHAR(40),(2)
    >     CITY VARCHAR(40),(3)
    >     STATE VARCHAR(2),(4)
    >   



ZIP CHAR(5) (5)  );


public class Address implements SQLData {
    public int num;
    public String street;
    public String city;
    public String state;
    public String zip;
    private String sql_type;

public String getSQLTypeName() {
    return sql_type;
}

public void readSQL(SQLInput stream, String type)
    throws SQLException {
    sql_type = type;
    num = stream.readInt();
    street = stream.readString();
    city = stream.readString();
    state = stream.readString();
    zip = stream.readString();
}

public void writeSQL(SQLOutput stream)
    throws SQLException {
    stream.writeInt(num);
    stream.writeString(street);
    stream.writeString(city);
    stream.writeString(state);
    stream.writeString(zip);
}

}

1 个答案:

答案 0 :(得分:0)

不是直接使用ORAData,而是使用ORADataFactory是一种方法。使用ORAData Create方法,我们可以访问类型元数据信息以帮助structdescriptor.getMetaData()函数,然后可以将其与值组合


from PyQt4.QtGui import *
from PyQt4.QtCore import *


class Series(QWidget):
    def __init__(self):
        super(Series, self).__init__()
        self.lb = QLabel('PYQT')


class SeriesHBox1(QWidget):
    def __init__(self, series):
        super(SeriesHBox1, self).__init__()
        self.vbox = QVBoxLayout()
        self.setLayout(self.vbox)
        self.vbox.addWidget(series.lb)


class SeriesHBox2(QWidget):
    def __init__(self, series):
        super(SeriesHBox2, self).__init__()
        self.hbox = QHBoxLayout()
        self.setLayout(self.hbox)
        self.hbox.addWidget(series.lb)


class Example(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 500, 300)
        box = QHBoxLayout()
        self.setLayout(box)

        box1 = QHBoxLayout()
        box2 = QHBoxLayout()
        box.addLayout(box1)
        box.addLayout(box2)

        series = Series()
        box1.addWidget(SeriesHBox1(series))
        box2.addWidget(SeriesHBox2(series))
        # box2.addWidget(SeriesHBox2(Series()))

        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
相关问题