你好我需要从oracle对象表(地址)获取值,并且我想用oracle类型(地址)映射java类(地址)。从Jframe中的按钮i打印数据。所以:
Sql:
create or replace
type address_t as object(
no varchar2(7),
str varchar2(40),
city varchar2(25),
country varchar2(25)
);
create table airp (id_pk number(5),
location address_t);
Java地址类:
import test.Test;
import java.sql.Connection;
import java.sql.SQLData;
import java.sql.SQLException;
import java.sql.SQLInput;
import java.sql.SQLOutput;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Address implements SQLData {
private String str;
private String no;
private String city;
private String country;
private String sql_type;
private Connection conn = null;
public Address(){
}
public Address(String sql_type, String no, String str, String city , String country){
this.sql_type = sql_type;
this.no = no;
this.str = str;
this.city = city;
this.country = country;
}
@Override
public String getSQLTypeName() throws SQLException {
return this.sql_type;
}
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sql_type = typeName;
no = stream.readString();
str = stream.readString();
city = stream.readString();
country = stream.readString();
}
@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeString(no);
stream.writeString(str);
stream.writeString(city);
stream.writeString(country);
}
@Override
public String toString(){
return sql_type+" "+no+" "+" "+city+" "+country;
}
}
和按钮:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
java.util.Map map = con.getTypeMap();
map.put("LI.ADDRESS_T", Class.forName("test.Address"));
con.setTypeMap((Map)map);
map = con.getTypeMap();
sql = "select * from aerop";
st = (OracleStatement)con.createStatement();
rs = (OracleResultSet)st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getObject(1));
}
} catch (SQLException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}}
我收到了下一个错误
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at test.Test.jButton1ActionPerformed
答案 0 :(得分:0)
con
或con.getTypeMap()
为null
。你为什么不调试它?