0
我正嘗試使用JDBC將XMLType列讀入Clob
類型變量。當我這樣做時,我收到一個錯誤....任何想法?使用JDBC讀取oracle數據庫中的XMLType列
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:197)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:269)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:490)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3353)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1883)
at oracle.jdbc.driver.OracleResultSet.getClob(OracleResultSet.java:358)
at persistance.FilmDAO.findFilmsWithXML(FilmDAO.java:626)
這是我的代碼:
public ArrayList<FilmBean> findFilmsWithXML() throws SQLException {
ArrayList<FilmBean> filmList = new ArrayList<FilmBean>();
try {
currentConnection = ConnectionPool.getInstance().getConnection();
String searchQuery = SqlHelper.getInstance().getSqlQuery(705);
System.out.println("Query: " + searchQuery);
currentStatement = currentConnection.prepareStatement(searchQuery);
currentResultSet = currentStatement.executeQuery();
while (currentResultSet.next())
{
FilmBean filmDTO = new FilmBean();
filmDTO.setFilmId(Integer.parseInt(currentResultSet.getString("PK_ID_FILM")));
filmDTO.setPoster(currentResultSet.getString("POSTER"));
filmDTO.setTitle(currentResultSet.getString("TITLE"));
filmDTO.setXml(currentResultSet.getClob("MYXML"));
filmList.add(filmDTO);
}
}
[...]
}
的setXml()
方法設置一個Clob
類型值到在模型中filmDTO
對象。
編輯
查詢缺少一個別名:
SELECT to_clob("MYXML") As MYCLOB, PK_ID_FILM, POSTER, TITLE FROM FILM Where MYXML is not null
這個返回' ',但是我認爲有一個SQL查詢的問題,因爲我想返回一個XMLType列的內容.... –
2012-07-30 18:04:38
沒關係!我改變了我的查詢:'SELECT to_clob(「MYXML」)作爲MYCLOB',它現在可以正常工作! – 2012-07-30 18:09:03